Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Problem using Top

Author  Topic 

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2004-06-30 : 14:35:35
Declare @vSQL varchar(8000),@emp_count int
set @vSQL = 'select top ' + convert(varchar,@emp_count) + ' * from emp_details where DateEntered < 6/30/2004 10:35:21 AM'

Execute(@vSQL)

this statment gives some error with the DateEnetered statement .if I remove the where clause it works

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-06-30 : 14:38:02
some error?

You probably need additional single quotes.

Instead of EXEC(@vSQL):

PRINT @SQL

Post the output here.

Tara
Go to Top of Page

drymchaser
Aged Yak Warrior

552 Posts

Posted - 2004-06-30 : 14:39:24
set @vSQL = 'select top ' + convert(varchar,@emp_count) + ' * from emp_details where DateEntered < ' + '''' + '6/30/2004 10:35:21 AM' + ''''
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-06-30 : 14:40:26
Ah, but now he doesn't learn why it was failing. Oh well.

Tara
Go to Top of Page

sqllearner
Aged Yak Warrior

639 Posts

Posted - 2004-06-30 : 15:06:27
working thanks..
Go to Top of Page
   

- Advertisement -