Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I´d like to do an exceutenonquery SQL Statement, that SELECTs ... WHERE FORMAT(Wiedervorlage,'yyyymmdd') <= ' " + WVDate + " ' "

WVDate is formatted in yyyymmdd and is a string.

 

The state. runs without errmsg, but datasets in myselection don´t fit to the <= WVDATE. Their still bigger ones inside.

 

I took this format , cause Formats like yyyy.mm.dd are not comparable, just as integers or strings, correct ???

Or has anybody any suggestion , perhaps , please ??

Sometimes you´ve got to make a silent Takedown .
Posted

You shouldn't compare the two as formatted strings, because that won't give a date comparison. "10" < "2" is true.

 

Would...

 

SELECTs ... WHERE Wiedervorlage <= #" + CDate(WVDate) + "#"

 

Work for you??

Posted

No !

 

It throws an Err in Date state expression. But there has to be any comfortable way to compare 2 ing Dates. Anything I try fails.

 

CAn someone give advice ??

Sometimes you´ve got to make a silent Takedown .
  • *Experts*
Posted

I'd use the Date compare if you can. You'll probably have to format your string date into the proper format. In the US, that format is MM/DD/YYYY. So the SQL should look like:

sql = "SELECT ... WHERE Wiedervorlage <= '" + WVDate.ToString("MM/dd/yyyy") + "'"

That should convert your DateTime variable, WVDate to a string in the format specified. Use single quotes (as shown) for SQL Server, or use "#" for Access. I think Oracle uses # as well. The end SQL should look like:

SELECT ... WHERE Wiedervorlage <= '09/29/2003'

 

If you really want to use the formatted version, you'll want to convert to a number:

sql = "SELECT ... WHERE CONVERT(int, FORMAT(Wiedervorlage, 'yyyymmdd')) <= " + WVDate.ToString("yyyyMMdd")

 

Note that in the above, I didn't put single quotes (or #) around the WVDate value. This is because you'd like to compare two numbers. I've never seen "Format" before - I'm guessing that's Access, but not really sure. If it is Access, change the CONVERT to something like CLng(...) or similar.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...