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.
4 10361
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..
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.
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.
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)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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.
...
|
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...
|
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:...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |