Skip to content

Problem with datatypes  #25

@JensAttermeyer

Description

@JensAttermeyer

I have a Problem with a storedprocedure and datatype conversion. If have the following storedprocedure:

ALTER PROCEDURE [dbo].[spGoodsMovement02]
@IDbName sysname
AS
DECLARE @text nvarchar(max)
IF EXISTS(SELECT * FROM sys.databases where name = @IDbName)
BEGIN
SET @text = N'SELECT TOP 1000
CAST(CONVERT(nchar, lb.Datum, 104) AS DATETIME) AS dateMovement,
lb.products_id AS productId,
lb.products_model AS productsModel,
lb.products_ean AS productsEan,
lb.orders_id AS ordersId,
o.ID AS orderID,
SUM(lb.Bewegung) AS movement,
AVG(lb.Bestand) AS stock,
pd.products_name AS productsName
FROM [' + @IDbName + '].[dbo].[Lager_Bewegungen] AS lb
INNER JOIN [' + @IDbName + '].[dbo].[Products_Description] AS pd ON lb.products_id = pd.products_id
LEFT OUTER JOIN [' + @IDbName + '].[dbo].[Orders] AS o ON o.orders_id = lb.orders_id
WHERE (lb.orders_id > 0)
GROUP BY CAST(CONVERT(nchar, lb.Datum, 104) AS DATETIME), lb.products_id, lb.products_model, lb.products_ean, pd.products_name, lb.orders_id, o.ID
HAVING (SUM(lb.Bewegung) <> 0)
ORDER BY dateMovement DESC,2,3,4,5,6,7'
EXEC (@text) END
PRINT 'NO DATABASE EXISTS'

If I call this storedprocedure in SQL Server Management Studio with a correct parameter for IDbName everything is ok and i get a result. If i call the procedure from my meteor app with Sql.sp() and the correct parameters i get the following error:
"The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value."
Has anybody an idee what is wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions