[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

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'.


0
ipendlebury
Asked:
ipendlebury
  • 2
  • 2
  • 2
2 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Select @SqlStatement = 'Select Top 1 @Updated = Updated From ' + @TableName + '  ORDER BY Updated Desc'

exec sp_ExecuteSQl  @SqlStatement, N'@Updated smalldatetime out',  @Updated out
0
 
Atlanta_MikeCommented:
Select @SqlStatement = 'Select Top 1 @Updated =  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'.
0
 
Atlanta_MikeCommented:
Sorry...

it should be

Select @SqlStatement = 'Select Top 1 @Updated =  Updated From ' + @TableName + '  ORDER BY Updated Desc'


Move the TOP 1
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
ipendleburyAuthor Commented:
Yes that was it. It seems an ilogical way to structure the systax though. Anyway, it's working now. Thanks for your help
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>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...
0
 
ipendleburyAuthor Commented:
Ah yes of course! Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now