ipendlebury
asked on
sp_executeSQL problem
Why doesn't this work in my Stored Procedure:
Select @SqlStatement = 'Select @Updated = Top 1 Updated From ' + @TableName + ' ORDER BY Updated Desc'
exec sp_ExecuteSQl @SqlStatement, N'@Updated smalldatetime out', @Updated out
It gives me the error: Incorrect syntax near the word 'Top'.
Select @SqlStatement = 'Select @Updated = Top 1 Updated From ' + @TableName + ' ORDER BY Updated Desc'
exec sp_ExecuteSQl @SqlStatement, N'@Updated smalldatetime out', @Updated out
It gives me the error: Incorrect syntax near the word 'Top'.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes that was it. It seems an ilogical way to structure the systax though. Anyway, it's working now. Thanks for your help
>Yes that was it. It seems an ilogical way to structure the systax though
no, because:
select top 1 @var1 = field1, @var2 = field2 etc from table etc...
no, because:
select top 1 @var1 = field1, @var2 = field2 etc from table etc...
ASKER
Ah yes of course! Thanks
exec sp_ExecuteSQl @SqlStatement, N'@Updated smalldatetime out', @Updated out
It gives me the error: Incorrect syntax near the word 'Top'.