Click here to Skip to main content
15,908,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, i want to code a dynamic SQL query yet syntax errors on my part get in my way. Please help me with the following:

SQL
SET @dynamicSQLCommand1 =
    'SELECT @CDT = SELECT TOP 1 DataTime FROM  DestinationDatabase.dbo.' + @CurrentTable + ' ORDER BY DataTime DESC '
    EXEC sp_executesql @dynamicSQLCommand1, N'@CDT nvarchar(500) OUTPUT', @CDT = @CurrentDataTime OUTPUT


I get the error with the SELECT TOP 1 part. Yet i can't really understand the syntax issue.
Thanks for help.
Posted

1 solution

Hi,

Check this one...


how to allocate table first value to a variable[^]

Hope this will help you.


Cheers
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900