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 |
Delinda
Constraint Violating Yak Guru
315 Posts |
Posted - 2009-10-27 : 08:27:10
|
I've list of table as follow,DERTimer_200910DERTimer_200909DERTimer_200908DERTimer_200907I want to make my sql statement dynamically as followdeclare @currDteInYYYYMM as varchar(10)set @currDteInYYYYMM='200910'select ECout from TRoutePrice, DERTimer_+ @currDteInYYYYMM + But i got an error as follow,Incorrect syntax near '+'.Can somebody help me what the syntax problem? |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-10-27 : 08:39:39
|
www.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail |
|
|
Delinda
Constraint Violating Yak Guru
315 Posts |
Posted - 2009-10-27 : 09:38:49
|
quote: Originally posted by madhivanan www.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail
My SDate is DateTimeafter using @sql, i gotselect ECout,Desn from TRoutePrice a, DERTimer_200907 b, TCounter c where b.SDate=Jul 18 2009how to make it sql above toselect ECout,Desn from TRoutePrice a, DERTimer_200907 b, TCounter c where b.SDate='7/18/2009'Currently, i usingSELECT @sql = ' select ECout,Desn' +' from TRoutePrice a, DERTimer_'+@currDteInYYYYMM+' b,' +' TCounter c' +' where b.SDate='+cast(@SalesDte as varchar(12))+'' |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-10-27 : 09:53:10
|
SELECT @sql = ' select ECout,Desn' +' from TRoutePrice a, DERTimer_'+@currDteInYYYYMM+' b,' +' TCounter c' +' where b.SDate='''+cast(@SalesDte as varchar(12))+''''MadhivananFailing to plan is Planning to fail |
|
|
Delinda
Constraint Violating Yak Guru
315 Posts |
Posted - 2009-10-27 : 09:59:29
|
quote: Originally posted by madhivanan SELECT @sql = ' select ECout,Desn' +' from TRoutePrice a, DERTimer_'+@currDteInYYYYMM+' b,' +' TCounter c' +' where b.SDate='''+cast(@SalesDte as varchar(12))+''''MadhivananFailing to plan is Planning to fail
Tq very much |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-10-27 : 10:08:30
|
quote: Originally posted by Delinda
quote: Originally posted by madhivanan SELECT @sql = ' select ECout,Desn' +' from TRoutePrice a, DERTimer_'+@currDteInYYYYMM+' b,' +' TCounter c' +' where b.SDate='''+cast(@SalesDte as varchar(12))+''''MadhivananFailing to plan is Planning to fail
Tq very much
You are welcome MadhivananFailing to plan is Planning to fail |
|
|
|
|
|
|
|