Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to use dates in WHERE in SQL Server
Message
 
 
To
10/06/2008 16:53:18
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01322704
Message ID:
01322934
Views:
19
>>>
>>>Dmitry,
>>>when you want to use Parameter you have to put Variable or Field name as parameter:
>>>
>>>lcDate = DATE(2008,6,1)
>>>cSqlCommand = "select * from mytable where myDateTimeField >= ?m.lcDate"
>>>
>>>** or
>>>CREATE CURSOR crsTest (Fld1 D)
>>>INSERT INTO crsTest VALUES (DATE(2008,6,1))
>>>cSqlCommand = "select * from mytable where myDateTimeField >= ?crsTest.Fld1"
>>>
>>>
>>>When you want to send Date as value built-in the string, then better use so called ISO standard (yyyymmdd) and pass it as string. SQL Server will parse it w/o any troubles. Sending DateTime that way is setting independent.
>>>
>>>
>>>lcDate = DATE(2008,6,1)
>>>cSqlCommand = "select * from mytable where myDateTimeField >= '"+DTOS(lcDate)+"'"
>>>*** result should look like this:
>>>** select * from mytable where myDateTimeField >= '20080601'
>>>
>>
>>Borislav,
>>
>>Thank you for the explanation and for your code. Since I want to send Date as a value built-in string, the method of using DTOS( lcDate) works for me. It works when retrieving the data from SQL Server.
>>
>>Unfortunately I have to maintain a different code when sending a SQL string to get data from VFP database. In my VFP database, I store dates in DATE type field whereas in SQL Server I use DATETIME type. Therefore sending cSqlCommand as following to VFP does not find the records:
>>
>>
>>cSqlCommand = "select * from mytable where myDateField >= '" + DTOS( lcDate) + "'"
>>
>>
>>
>>Again, thank you.
>
>Dmitry,
>Whether the backend is VFP, SQL server, Oracle ... using parameters work.
>
>cSqlCommand = "select * from mytable where myDateField >= ?m.ldDate"
>
>Cetin

But the problem I am having is that I have to pass the variable m.ldDate to the function that actually calls SQL Server (using SPT). I am trying to find a way to create a built-in string that includes the Date Variable without having to pass the variable.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform