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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SELECT , WHERE , DATE RANGE !

Author  Topic 

abstrused00388
Starting Member

4 Posts

Posted - 2011-06-29 : 01:11:15
Hey ppl ,
i am new to using SQL

all i have to do is the following steps
1.connect a database in VB using the db grid control (via adodc) Done !

2. I need a query statement which scans for two dates and list the all the columns within the date . "PROBLEM HERE"

i have the database with date time format of MM-dd-yyyy hh:mm:ss AM/PM

so i wrote the statement

Adodc1.RecordSource = "SELECT * FROM CM126 WHERE dt<=12/10/2010 AND dt>= 10/10/2010"


i have tried all possible ways of giving date and time but the only one which did not pop up any error message was this format .. all the others said "SYNTAX ERROR/operator missing"

can someone let me know how to search for a date range ..


With regards,

Santhosh Kumar

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-06-29 : 02:00:52
if the data type of column dt is datetime, specify the date in YYYYMMDD and enclosed it in single quote


Adodc1.RecordSource = "SELECT * FROM CM126 WHERE dt <= '20101012' AND dt>= '20101010'"



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

abstrused00388
Starting Member

4 Posts

Posted - 2011-06-29 : 02:16:58
hi !

i got that just in time and u too have replied the same :)

can u let me know how to use the input from user (say 'text1.text') as my search date instead of my own date in the code !! ??



With regards,

Santhosh Kumar
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-06-29 : 02:34:35
i am not very familiar with the VB syntax, probably something like this


Adodc1.RecordSource = "SELECT * FROM CM126 WHERE dt <= '" & text1.text & "' AND dt>= '" & text2.text & "'"


basically you need to concatenate the date input (format it to YYYYMMDD if it is not in that format) to the query.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

abstrused00388
Starting Member

4 Posts

Posted - 2011-06-29 : 02:50:16
Dear Kh !

Did nt work out well :( !!

please try for me .. !

cant someone help ?


With regards,

Santhosh Kumar
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-06-29 : 03:39:24
quote:
Originally posted by abstrused00388

Dear Kh !

Did nt work out well :( !!

please try for me .. !

cant someone help ?


With regards,

Santhosh Kumar


What did you mean? Did you get any error or unexpected result?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

abstrused00388
Starting Member

4 Posts

Posted - 2011-06-29 : 03:47:53
" Data type mismatch in criteria expression "

With regards,

Santhosh Kumar
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-06-29 : 05:17:34
What is the datatype of dt?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -