Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Variable Question

Status
Not open for further replies.

chrisgeek

Technical User
Oct 16, 2008
25
0
0
US
My issue here is I don't truly understand how variables work. I get that you create one and give it some data and it uses that in the query. My issue is with a datetime variable SQL is storing it as 2010-08-01 00:00:00 and when I give it that data in crystal or sql everything runs fine. However my application is passing the date as 08-01-2010 00:00:00 thus causing an error. How do I get this data to conform either by cast and convert or some process. Any help you can provide is greatly appreciated.
 
Is your field a date or a string?

Make sure the variable matches the same type.

You can also convert the string, by extracting sub strings, and then building them with a date function.

provide an example of what you are trying to do

Editor and Publisher of Crystal Clear
 
The field is datetime what I did was change the stored procedure to select table.field, CONVERT (Nvarchar, 10, 101) which should change the select to US style dates of MM/DD/YYYY and allow everything to flow smoothly. I can't test it as of now due to server maintenance but I think this is going to be effective.

The problem is all the instructions said this:
SELECT CONVERT (NVARCHAR (10), 101)
When I needed to enter
SELECT table.field, CONVERT (NVARCHAR (10), table.field, 101)
FROM table.

For me I couldn't figure out exactly what was happening when and it took a while to decipher it because the code descriptions weren't clear. This may also require the getdate() function but I'm not sure yet how the variables will function without default values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top