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 |
|
smitha
Posting Yak Master
100 Posts |
Posted - 2009-12-02 : 06:04:42
|
| Hi,I am using select statement in VBA and I am getting the data from sql database. My code goes like thissCrit = "where DATE1 = #" & Format$(Date, "DD/MM/yyyy") & "#"Set rsRepQry = New ADODB.Recordset rsRepQry.Open "Select * from E1_SHIFTA " & sCrit, conDB, adOpenStatic, adLockReadOnlybut when I run this, I am getting the error INCORRECT SYNTAX NEAR # can anyone help this |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-12-02 : 07:17:20
|
| I don't think you need all that. SQL will recognize '20091231' as well as 12/31/2009. Also, SQL uses "'" for dates, not the # like Access does. sCrit = "where DATE1 = '" Date & "'" Everyday I learn something that somebody else already knew |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-12-02 : 07:23:21
|
| 1 It is better you use stored procedure with parameters2 Dont format the date in ambigious dd/mm/yyyy format. Better use dd-MMM-yyyy or YYYYMMDDMadhivananFailing to plan is Planning to fail |
 |
|
|
smitha
Posting Yak Master
100 Posts |
Posted - 2009-12-04 : 00:26:10
|
quote: Originally posted by jimf I don't think you need all that. SQL will recognize '20091231' as well as 12/31/2009. Also, SQL uses "'" for dates, not the # like Access does. sCrit = "where DATE1 = '" Date & "'" Everyday I learn something that somebody else already knew
Thanks I got the result but only with single quotes for DateSmitha |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-12-04 : 02:18:33
|
quote: Originally posted by smitha
quote: Originally posted by jimf I don't think you need all that. SQL will recognize '20091231' as well as 12/31/2009. Also, SQL uses "'" for dates, not the # like Access does. sCrit = "where DATE1 = '" Date & "'" Everyday I learn something that somebody else already knew
Thanks I got the result but only with single quotes for DateSmitha
It means you didn't consider my pointsYou will get errors for the dates desc 19, nov 20, etcMadhivananFailing to plan is Planning to fail |
 |
|
|
smitha
Posting Yak Master
100 Posts |
Posted - 2010-01-06 : 06:46:02
|
| I want to carry this forward. I am not getting the correct result for this statement.sCrit = "where DATE1 ='Date&'"Smitha |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-06 : 06:58:36
|
| sCrit = "where DATE1 = '" & Format$(Date, "yyyy-MM-DD") & "'" |
 |
|
|
|
|
|
|
|