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.
| Author |
Topic |
|
alperozgur
Starting Member
16 Posts |
Posted - 2005-03-03 : 07:50:22
|
| Hi;Here is my problem. I have a query as below :declare @SAYI AS INTUSE SUNDBSELECT @SAYI=count(btl_date) FROM BPG_DATES WHERE period=2 and btl_date=1 and year(n_date)=2004USE SUNDB1SELECT TOP @SAYI * FROM BPG_DATES WHERE period=2 and btl_date=1 and year(n_date)=2005GOwhen i run this query it gives the error : Server: Msg 170, Level 15, State 1, Line 6Line 6: Incorrect syntax near '@SAYI'.need help urgent... |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-03-03 : 07:56:09
|
you can't use the top operator in this way.you can do however:set rowcount @SAYI -- set the number of rows to be processed/returnedSELECT * FROM BPG_DATES WHERE period=2 and btl_date=1 and year(n_date)=2005set rowcount 0 -- set it back to return allGo with the flow & have fun! Else fight the flow |
 |
|
|
Xerxes
Aged Yak Warrior
666 Posts |
Posted - 2005-03-03 : 10:30:05
|
quote: Originally posted by spirit1 you can't use the top operator in this way.you can do however:set rowcount @SAYI -- set the number of rows to be processed/returnedSELECT * FROM BPG_DATES WHERE period=2 and btl_date=1 and year(n_date)=2005set rowcount 0 -- set it back to return allGo with the flow & have fun! Else fight the flow 
Mladen, Don't you mean this?:set rowcount=@SAYI -- set the number of rows to be processed/returnedSELECT * FROM BPG_DATES WHERE period=2 and btl_date=1 and year(n_date)=2005set rowcount 0 -- set it back to return allSemper fi, XERXES, USMC(Ret.)------------------------------------------------------The Marine Corps taught me everything but SQL! |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-03-03 : 10:44:28
|
| Are you doubting the flawless syntaxity of Spirit1?!?try these 2 statements and see which one works:set rowcount 1set rowcount = 1Be One with the OptimizerTG |
 |
|
|
Xerxes
Aged Yak Warrior
666 Posts |
Posted - 2005-03-03 : 10:50:10
|
Mladen & TG..... I am wrong . Mladen's syntaxity was flawless . Oooops. Semper fi, XERXES, USMC(Ret.)------------------------------------------------------The Marine Corps taught me everything but SQL! |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-03-03 : 11:03:30
|
heh.... Go with the flow & have fun! Else fight the flow |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-03-04 : 10:41:20
|
quote: Originally posted by alperozgur Hi;Here is my problem. I have a query as below :declare @SAYI AS INTUSE SUNDBSELECT @SAYI=count(btl_date) FROM BPG_DATES WHERE period=2 and btl_date=1 and year(n_date)=2004USE SUNDB1SELECT TOP @SAYI * FROM BPG_DATES WHERE period=2 and btl_date=1 and year(n_date)=2005GOwhen i run this query it gives the error : Server: Msg 170, Level 15, State 1, Line 6Line 6: Incorrect syntax near '@SAYI'.need help urgent...
Try thisdeclare @SAYI AS INTUSE SUNDBSELECT @SAYI=count(btl_date) FROM BPG_DATES WHERE period=2 and btl_date=1 and year(n_date)=2004USE SUNDB1Exec('SELECT TOP '+@SAYI+' * FROM BPG_DATES WHERE period=2 and btl_date=1 and year(n_date)=2005')GOMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|