473,395 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

SQL Where Clause Date Parameter

benchpolo
142 100+
I wrote a SQL script with a rxfilldate (mm/dd/yyyy format) parameter in WHERE clause. Is there way to automate the where clause to pick up the previous months data.

For example: DATEPAID BETWEEN '09/01/2007' AND '09/30/2007'

where rxfilldate,112) BETWEEN
convert(varchar(2),datepart(mm,dateadd(month,-1,getdate()))) + '-01-' +
convert(varchar(4),datepart(yyyy,dateadd(month,-1,getdate())))
AND convert(varchar(20),getdate(),10)

Thanks.
Oct 22 '07 #1
4 10361
amitpatel66
2,367 Expert 2GB
I wrote a SQL script with a rxfilldate (mm/dd/yyyy format) parameter in WHERE clause. Is there way to automate the where clause to pick up the previous months data.

For example: DATEPAID BETWEEN '09/01/2007' AND '09/30/2007'

where rxfilldate,112) BETWEEN
convert(varchar(2),datepart(mm,dateadd(month,-1,getdate()))) + '-01-' +
convert(varchar(4),datepart(yyyy,dateadd(month,-1,getdate())))
AND convert(varchar(20),getdate(),10)

Thanks.
Is your above query not working??
Make use of sysdate and subtract it by one month and get the first day and the last day of that month to get the previous months value..
Oct 23 '07 #2
benchpolo
142 100+
somehow, i am not getting any data.. my guess is because the date format for my rxfilldate is yyyymmdd, and i'm not quite sure how to write the statement based on yyyymmdd format.
Oct 23 '07 #3
benchpolo
142 100+
Below is the actual WHERE CLAUSE im using in my script

CONVERT(varchar(8),pd.rxfilldate,112) BETWEEN
convert(varchar(4),datepart(yyyy,dateadd(month,-1,getdate())))+
convert(varchar(2),datepart(mm,dateadd(month,-1,getdate())))+ '-01-'
AND convert(varchar(20),getdate(),10)

Unfortunately, I am not getting date from last month. Please advise. Thanks.
Oct 23 '07 #4
benchpolo
142 100+
Here's another WHERE CLAUSE statement where the rxfilldate1 format is mm/dd/yy

WHERE convert(varchar(8),pd.rxfilldate1,112) BETWEEN convert(varchar(2),datepart(mm,dateadd(month,-1,getdate()))) + '-01-' +
convert(varchar(4),datepart(yyyy,dateadd(month,-1,getdate())))
AND convert(varchar(20),getdate(),10)
Oct 23 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Berend | last post by:
I am trying to pass multi values into a where clause with an in clause in a store procedure to use in a Crystal report. This can change depending on the user. Maybe there is another way to pass...
2
by: scottelkin | last post by:
I am trying to find all affiliates that have more commissions from this week to the prior week. The problem is in the having part where "aff2.affiliateid = aff.affiliateid". SQL Server just...
1
by: Alex Satrapa | last post by:
I have a table from which I'm trying to extract certain information. For historical reasons, we archive every action on a particular thing ('thing' is identified, funnily enough, by 'id'). So the...
4
by: Brian Shannon | last post by:
I have 3 combo boxes and two date text boxes on a .aspx page. The user can fill in any of the 5 controls or none to filter a datagrid. I was hoping someone could explain how to efficiently build...
7
by: Britney | last post by:
Original code: this.oleDbSelectCommand1.CommandText = "SELECT TOP 100 user_id, password, nick_name, sex, age, has_picture, city, state, " + "country FROM dbo.users WHERE (has_picture = ?) AND (sex...
26
by: GreatAlterEgo | last post by:
Hi, This is my query which is embedded in a COBOL program. EXEC SQL SELECT DATE, AGE, DURATION, AMT INTO :LDATE, :L.AGE, :L.DURATION, :L.AMT FROM TAB1 WHERE CODE = :KEY.CODE AND...
1
by: 2D Rick | last post by:
I want to open a report using OpenReport and passing it a Where Clause with multiple criteria. I know the Where Clause below is way off but it conveys what I need. Dates are of string type. ...
9
by: =?Utf-8?B?VHlsZXIgUy4=?= | last post by:
I have VS.Net with SQL Server 2005 and I'm developing a windows application in C# and I'm trying to write a query to use an EXCEPT clause and I'm getting an error saying the EXCEPT clause isn't...
20
by: billmaclean1 | last post by:
I need to write a stored procedure that selects from a table and returns the result set. I don't always know the TableSchema that I need to use when qualifying the table at run-time Example:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.