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 |
|
sven2
Yak Posting Veteran
57 Posts |
Posted - 2009-12-04 : 04:54:08
|
| Hello,How can I change a date in a SQL to a variable?For example:This is a part of a working SQL:strSQL = strSQL & " WHERE (DATEADD(Month, Item_stam.Geldigheidsperiode, Personeels_evaluaties.Toevoegdatum) < CONVERT(DATETIME, '2009-12-04', 102))"This doesn't work anymore:datetoday = datestrSQL = strSQL & " WHERE (DATEADD(Month, Item_stam.Geldigheidsperiode, Personeels_evaluaties.Toevoegdatum) < CONVERT(DATETIME, '" & datetoday & "', 102))"What is wrong with the second SQL?Thanks in advance,Sven. |
|
|
kbhere
Yak Posting Veteran
58 Posts |
Posted - 2009-12-04 : 05:18:45
|
| The problem is here,You are trying to convert datetime datatype to datetime..CONVERT(DATETIME, '" & datetoday & "', 102)replace it withCONVERT(VARCHAR, '" & datetoday & "', 102)Balaji.K |
 |
|
|
sven2
Yak Posting Veteran
57 Posts |
Posted - 2009-12-04 : 05:53:43
|
| Hello,thank you ... like you wrote, convert datetime to datetime isn't working. I've got it working.Best regards,Sven. |
 |
|
|
kbhere
Yak Posting Veteran
58 Posts |
Posted - 2009-12-04 : 06:02:12
|
quote: Originally posted by sven2 Hello,thank you ... like you wrote, convert datetime to datetime isn't working. I've got it working.Best regards,Sven.
Ok.. You are always Welcome!!Balaji.K |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-12-04 : 07:28:46
|
| It is better you use parameter instead of concatenating the valueMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|