Showing posts with label date. Show all posts
Showing posts with label date. Show all posts

Friday, March 9, 2012

How to compare vachar which type :20060324225008 with Datetime?

in my SQL 2000

the column importDate contain Date as a vachar , type is 20060324225008 ( 2006 -year , 03-month, 24-day)

I want to compare this column with today's date, how to transform it?

how to return value 20060324 not 20060324225008?

thank you

Grab the column as a string

string rawNumber = "20060324";

DateTime dtTime = Convert.ToDateTime(rawNumber);

Does it work?

|||

how can I get the value of column = 20060324, is was20060324225008 not 20060324

the problem is how to get 20060324 only

thank you

|||

Select LEFT(yourColumn,8) as newValue FROM yourTable

After this, you can use one of datetime functions to compare this date part with today's date part.

Wednesday, March 7, 2012

How to compare the date in SQL Server 2000?

Hi all,
I have encountered a problem that I can't compare the date in SQL Server 2000.
But I know that maybe I have used "datetime" as data type for that field.
My question is that, how can I get ONLY the "date" in stead of "datetime" from the database?
Your attention is appreciated!
Thank you.

Regards,
katszetoYou can use Convert to get the date as a string, but SQL itself doesn't have a date only type. You need to use a temp var or datediff functions if you want to ignore the time.|||Is it first get the value from the database and then convert it to String and do comparison?|||you should always strive to avoid string comparisons for dates, what/where would be the ideal code you are looking for and we'll see what sort of solution you should have?|||Exactly what are you trying to do?
Give some requirements and then perhaps we can
give some more relevant help.|||One option:
Convert the date to a varChar specifying a format that does not involve time. Then CAST() the varchar back to datetime

WHERE CAST(CONVERT(varChar, myField, 112) AS SmallDateTime) = '1900/1/1'

Cheers
Ken|||Now, I want to enter a date as a parameter and search from the database.
Then display the result in the datagrid.
And the SQL Command is :Select * from [table] where date = [parameter]
I have tried that if I also input the date and time as parameter,
no record is found!!|||


CREATE PROC usp_myProc

@.Param smallDateTime

AS

-- Do some SELECT here

WHERE
CAST(CONVERT(varChar, myField, 112) AS SmallDateTime) = @.Param

Cheers
Ken|||You'd be much better off using DateDiff for that sort of operation.

How to compare just the Date portion of DateTime fields

What's the best way to compare just the Date portions of datetime
fields (ignore the time)
lateFlag = case
when TargetEndDate is null then 'N'
when TargetEndDate < getutcdate() then 'Y'
else 'N'
end
RonUse the CONVERT function to get the desired component of a date time.
--
HTH,
SriSamp
Email: srisamp@.gmail.com
Blog: http://blogs.sqlxml.org/srinivassampath
URL: http://www32.brinkster.com/srisamp
"RonL" <sal_paradise_93@.yahoo.com> wrote in message
news:1145850793.160785.158820@.t31g2000cwb.googlegroups.com...
> What's the best way to compare just the Date portions of datetime
> fields (ignore the time)
> lateFlag = case
> when TargetEndDate is null then 'N'
> when TargetEndDate < getutcdate() then 'Y'
> else 'N'
> end
>
> Ron
>|||If you want a condition that tells if TargetEndDate has a date
part before the date part of getutcdate(), you can do it while
still taking advantage of any useful index on TargetEndDate
by checking whether TargetEndDate with its time part is
before the date-only part of getutcdate() this way:
TargetEndDate < dateadd(day,datediff(day,0,getutcdate())
,0)
The time part of TargetEndDate can't change whether it
is before a date-only value or not.
Steve Kass
Drew University
RonL wrote:

>What's the best way to compare just the Date portions of datetime
>fields (ignore the time)
>lateFlag = case
> when TargetEndDate is null then 'N'
> when TargetEndDate < getutcdate() then 'Y'
> else 'N'
> end
>
>Ron
>
>|||Or better yet a couple datetime functions:
select dateadd(d, datediff(d, 0, current_timestamp), 0)
so the OP's snippet of code would be something like
lateFlag =
case
when TargetEndDate is null then 'N'
when dateadd(d,datediff(d,0,TargetEndDate),0)
<
dateadd(d,datediff(d,0,getutcdate()),0) then 'Y'
else 'N'
end
*mike hodgson*
http://sqlnerd.blogspot.com
SriSamp wrote:

>Use the CONVERT function to get the desired component of a date time.
>--
>HTH,
>SriSamp
>Email: srisamp@.gmail.com
>Blog: http://blogs.sqlxml.org/srinivassampath
>URL: http://www32.brinkster.com/srisamp
>"RonL" <sal_paradise_93@.yahoo.com> wrote in message
>news:1145850793.160785.158820@.t31g2000cwb.googlegroups.com...
>
>
>|||Don't use CONVERT for this. Use the DateAdd and DateDiff version, (it's
already been posted twice, so I won't repeat)
The reason for this is that Convert writes the result to a memory page.
This means SLOW AND EXPENSIVE! Using the DateAdd and DateDiff functions
does not result in a page write, it only uses a small amount of CPU whilst
running the functions, and there is no conversion of datatypes taking place.
Regards
Colin Dawson
www.cjdawson.com
"SriSamp" <ssampath@.sct.co.in> wrote in message
news:etjXwS1ZGHA.1192@.TK2MSFTNGP04.phx.gbl...
> Use the CONVERT function to get the desired component of a date time.
> --
> HTH,
> SriSamp
> Email: srisamp@.gmail.com
> Blog: http://blogs.sqlxml.org/srinivassampath
> URL: http://www32.brinkster.com/srisamp
> "RonL" <sal_paradise_93@.yahoo.com> wrote in message
> news:1145850793.160785.158820@.t31g2000cwb.googlegroups.com...
>|||Great. Thanks.
Ron

How to compare if date is in between two dates.

I have a report that binds to view. Every record has an "Employee Joining date" date field with it.

I have to filter out records ; whose joining date is with in two different dates.

How will i set "selection Criteria"; as i dont have any idea of the crystal reports syntax.

SOme refrence or sample will be valuable for me.

PLz. reply soon

Thanks in advanceGive the folg. in ur selection formula

{join_date} in {?start} to {?end}

join_date => ur database field

start, end => parameter fields

Hope this will work|||what i see is that the date in crystal report is consist of time too...
so how to get rid of the time, so that i can get only the date?|||what i see is that the date in crystal report is consist of time too...
so how to get rid of the time, so that i can get only the date?

Use Cdate Function

Cdate(DateTimeField)

how to compare date periods ?

Hi,
I need to compare 2 periods (start date / end date) in order to find out if the first period overlaps or in included in the second period.
any idea ?
thankswhere [P1].[StartDate] <= [P2].[EndDate]
and [P1].[EndDate] >= [P2].[StartDate]|||blindman, that's only a complete overlap (2nd period completely within the first)

what about partial overlaps

july 15 to august 15 partially overlaps august 1 to august 31|||What about:

select case
when P1.Startdate between P2.startdate and P2.Enddate and P1.Enddate between P2.startdate and P2.Enddate then 'Include'
when P1.Startdate between P2.startdate and P2.Enddate or P1.Enddate between P2.startdate and P2.Enddate then 'OverLaps'
else 'Does not Overlap or is included'
end|||nice, DMWCincy, but you're missing blindman's conditions :)

this topic has been covered before, e.g. http://www.dbforums.com/t1147226.html, but no point looking that up, because this site has lost its archives for old posts (which is one of the reasons i'll be leaving shortly)|||blindman, that's only a complete overlap (2nd period completely within the first)

what about partial overlaps

july 15 to august 15 partially overlaps august 1 to august 31

Actually, blindman's logic is correct and will handle partial overlaps such as the scenario you specified as well as complete overlaps.|||blindman, that's only a complete overlap (2nd period completely within the first)

what about partial overlaps

july 15 to august 15 partially overlaps august 1 to august 31

Since blindman is offline, I'll note that I use the same technique, and it will find partial overlaps, including your sample. Substituting your values into his WHERE clause:

where july 15 <= august 31
and august 15 >= august 1

You can see that your sample record would be returned by his WHERE clause.

Edit: Sorry RogerWilco, your post wasn't there when I started typing.|||Actually, blindman's logic is correct .aaargh, you're right, i read it wrong

sorry :o :o|||OK, now I don't get to post some snooty and tactless comment to Rudy about how my code DOES work, 'cause you guys already took all the fun away.

--Humph!--|||that's okay, i feel sufficiently blindman-chastised already|||I can't believe it was so easy !
thanks blindman|||this topic has been covered before, e.g. http://www.dbforums.com/t1147226.html, but no point looking that up, because this site has lost its archives for old posts (which is one of the reasons i'll be leaving shortly)
Sorry to hear you will be leaving us rudeboy.

But I just can't help myself - don't you keep copies of posts like this?:p|||yes, i do :) :)

and how did you know rudeboy was one of my nicknames?

will i be seeing you on one of the other sites i mentioned in this thread (http://www.dbforums.com/t1198344.html)?|||and how did you know rudeboy was one of my nicknames?
I imagine your friends have the same colossal imagination as I :p


will i be seeing you on one of the other sites i mentioned in this thread (http://www.dbforums.com/t1198344.html)?Ever so kind of you to ask - I must admit Tek Tips regularly comes up on Googles - wish they would get rid of the little drop-down-over-the-text-you-are-reading-just-as-it-gets-interesting box. I might indeed have a look - as you know I have a penchant for ANSII SQL also.

I quite like playing around on this (http://www.experts-exchange.com/)site (another that came up regularly on searches, so I joined). They give you points and from these you are assigned worth. It's ever so self validating. I'm not sure that there are the sort of heavy weights in residence as there are on this forum though.

I see from your link a lot of you are going to be moving. I may not post in this forum often but I visit frequently - I've learnt lots and have been tremendously entertained, expecially when pickings are poor and you are forced to turn on one another ;)

I hope you all do well - drop us a post in the baby db forum (AKA Access) to let us know your new roaming grounds.|||...They give you points and from these you are assigned worth. It's ever so self validating. devshed forums are like that, you build up "rep points" (reputation) which you can then spread around to others

see http://forums.devshed.com/member.php?userid=22396

How to Compare Date every day automatically?

I got various Job Details listed in my table. I have set all jobs in a
such a way that they will be LIVE when Flag=1 and EXPIRED when Flag=0.
But how can I compare the Expiry Job Date with the Current Date and
Update Flag=0 automatically when its expired. I probably need compare
everyday.
I have no clue how to do this. I looked at Triggers but may be its not
the one i'm looking for..
Is this possible in SQL Server?
Thanks in Advance for your time and helpsomething like this:
update jobs
set flag=0
where expiry_date=convert(varchar(8),getdate()
,112)
set up a job to run this update daily.
however, it seems redundant, to have both the expiry date and the flag in
the table.
dean
"savvy" <johngera@.gmail.com> wrote in message
news:1138960957.385296.309670@.g47g2000cwa.googlegroups.com...
>I got various Job Details listed in my table. I have set all jobs in a
> such a way that they will be LIVE when Flag=1 and EXPIRED when Flag=0.
> But how can I compare the Expiry Job Date with the Current Date and
> Update Flag=0 automatically when its expired. I probably need compare
> everyday.
> I have no clue how to do this. I looked at Triggers but may be its not
> the one i'm looking for..
> Is this possible in SQL Server?
> Thanks in Advance for your time and help
>|||Thank you very much for your help Dean
I created a job in SQL Server and its working fine
Thanks in once again

how to compare current date with sql db datetime data type

Hi,

I am using one datetime data type ( name: date_added ) and getdate() as default value. I want to display only those records added today. How I can compare current date with date_added.

Thanks
ManojSELECT * FROM tablename WHERE CONVERT(varchar(10),date_added,112)=CONVERT(varchar(10),GetDate(),112)

This converts both dates to yyyymmdd format, and then compares them. A better alternative might be:

SELECT * FROM tablename WHERE date_added>=CONVERT(datetime,CONVERT(varchar(10),GetDate(),112))

This presumes that there are no records added later than today. It compares the date_added to getdate() return value, converted to yyyymmdd, then converted back to a date.

How to compare 3 dates

I have 3 different dates from same table same coloumn. I want to
compare these 3 dates and find out the latest date. How can I do this?
Thanks for help!
SELECT MAX(date_column) FROM table
<superbaby@.gmail.com> wrote in message
news:1171639291.878469.56900@.m58g2000cwm.googlegro ups.com...
>I have 3 different dates from same table same coloumn. I want to
> compare these 3 dates and find out the latest date. How can I do this?
> Thanks for help!
>
|||On Feb 16, 4:32 pm, "Aaron Bertrand [SQL Server MVP]"
<ten...@.dnartreb.noraa> wrote:
> SELECT MAX(date_column) FROM table
> <superb...@.gmail.com> wrote in message
> news:1171639291.878469.56900@.m58g2000cwm.googlegro ups.com...
>
>
> - Show quoted text -
Thank you very much!, but I need to update this max(date_coloumn) to
one of coloumn in another table. So I write like this:
update compnay
set datefield3 = max(a.freedateField_02)
inner join aTabel on aTable.customerID=compnayID and aTable.type in
(200, 203, 205)
But It returns an error: An aggregate may not appear in the set list
of an UPDATE statement.
Sorry for my stupid question. I am really bad in SQL.
|||> Thank you very much!, but I need to update this max(date_coloumn) to
> one of coloumn in another table. So I write like this:
> update compnay
> set datefield3 = max(a.freedateField_02)
> inner join aTabel on aTable.customerID=compnayID and aTable.type in
> (200, 203, 205)
> But It returns an error: An aggregate may not appear in the set list
> of an UPDATE statement.
> Sorry for my stupid question. I am really bad in SQL.
Why would you need to do this? Are you going to run this UPDATE statement
every time any row in aTabel changes? You can always get that MAX date from
a query, so I see absolutely no need to replicate it to another table every
time it changes. Just include that join in your queries or create a view
that does the same.
A
|||On Feb 16, 5:27 pm, "Aaron Bertrand [SQL Server MVP]"
<ten...@.dnartreb.noraa> wrote:
>
>
> Why would you need to do this? Are you going to run this UPDATE statement
> every time any row in aTabel changes? You can always get that MAX date from
> a query, so I see absolutely no need to replicate it to another table every
> time it changes. Just include that join in your queries or create a view
> that does the same.
> A
Yes, I have a report which is hard coded to use the coloumn only from
table called Company. But the date inforamtion is stored into another
table (aTable). I actually need to schdeule it and run it
automatically.
In the aTable, there 3 different type records contains the different
date for the same company. I need to update the lastest date to the
Company table which has the same companyID in the aTable.CustomerID.
|||> Yes, I have a report which is hard coded to use the coloumn only from
> table called Company.
Then I would suggest changing the report. Or creating a new one and using
that one instead.

> I actually need to schdeule it and run it automatically.
And it's okay if the report returns incorrect data in between your schedule?
A

How to compare 3 dates

I have 3 different dates from same table same coloumn. I want to
compare these 3 dates and find out the latest date. How can I do this?
Thanks for help!SELECT MAX(date_column) FROM table
<superbaby@.gmail.com> wrote in message
news:1171639291.878469.56900@.m58g2000cwm.googlegroups.com...
>I have 3 different dates from same table same coloumn. I want to
> compare these 3 dates and find out the latest date. How can I do this?
> Thanks for help!
>|||On Feb 16, 4:32 pm, "Aaron Bertrand [SQL Server MVP]"
<ten...@.dnartreb.noraa> wrote:
> SELECT MAX(date_column) FROM table
> <superb...@.gmail.com> wrote in message
> news:1171639291.878469.56900@.m58g2000cwm.googlegroups.com...
>
>
> - Show quoted text -
Thank you very much!, but I need to update this max(date_coloumn) to
one of coloumn in another table. So I write like this:
update compnay
set datefield3 = max(a.freedateField_02)
inner join aTabel on aTable.customerID=compnayID and aTable.type in
(200, 203, 205)
But It returns an error: An aggregate may not appear in the set list
of an UPDATE statement.
Sorry for my stupid question. I am really bad in SQL.|||> Thank you very much!, but I need to update this max(date_coloumn) to
> one of coloumn in another table. So I write like this:
> update compnay
> set datefield3 = max(a.freedateField_02)
> inner join aTabel on aTable.customerID=compnayID and aTable.type in
> (200, 203, 205)
> But It returns an error: An aggregate may not appear in the set list
> of an UPDATE statement.
> Sorry for my stupid question. I am really bad in SQL.
Why would you need to do this? Are you going to run this UPDATE statement
every time any row in aTabel changes? You can always get that MAX date from
a query, so I see absolutely no need to replicate it to another table every
time it changes. Just include that join in your queries or create a view
that does the same.
A|||On Feb 16, 5:27 pm, "Aaron Bertrand [SQL Server MVP]"
<ten...@.dnartreb.noraa> wrote:
>
>
>
> Why would you need to do this? Are you going to run this UPDATE statement
> every time any row in aTabel changes? You can always get that MAX date fr
om
> a query, so I see absolutely no need to replicate it to another table ever
y
> time it changes. Just include that join in your queries or create a view
> that does the same.
> A
Yes, I have a report which is hard coded to use the coloumn only from
table called Company. But the date inforamtion is stored into another
table (aTable). I actually need to schdeule it and run it
automatically.
In the aTable, there 3 different type records contains the different
date for the same company. I need to update the lastest date to the
Company table which has the same companyID in the aTable.CustomerID.|||> Yes, I have a report which is hard coded to use the coloumn only from
> table called Company.
Then I would suggest changing the report. Or creating a new one and using
that one instead.

> I actually need to schdeule it and run it automatically.
And it's okay if the report returns incorrect data in between your schedule?
A|||You cannot use an aggregate function on the LHS of the SET clause in an
UPDATE statement. As an alternative, you could try:
UPDATE Company
SET date3 = ( SELECT MAX( a1.freedate2 )
FROM atable a1
WHERE a1.CompanyId = Company.CompanyId
AND a1.type IN ( 200, 203, 205 ) )
WHERE EXISTS ( SELECT *
FROM atable a1
WHERE a1.CompanyId = Company.CompanyId
AND a1.type IN ( 200, 203, 205 ) ) ;
Anith|||On Feb 16, 7:54 pm, "Anith Sen" <a...@.bizdatasolutions.com> wrote:
> You cannot use an aggregate function on the LHS of the SET clause in an
> UPDATE statement. As an alternative, you could try:
> UPDATE Company
> SET date3 = ( SELECT MAX( a1.freedate2 )
> FROM atable a1
> WHERE a1.CompanyId = Company.CompanyId
> AND a1.type IN ( 200, 203, 205 ) )
> WHERE EXISTS ( SELECT *
> FROM atable a1
> WHERE a1.CompanyId = Company.CompanyId
> AND a1.type IN ( 200, 203, 205 ) ) ;
> --
> Anith
Thank you, it works very well.

How to compare 3 dates

I have 3 different dates from same table same coloumn. I want to
compare these 3 dates and find out the latest date. How can I do this?
Thanks for help!SELECT MAX(date_column) FROM table
<superbaby@.gmail.com> wrote in message
news:1171639291.878469.56900@.m58g2000cwm.googlegroups.com...
>I have 3 different dates from same table same coloumn. I want to
> compare these 3 dates and find out the latest date. How can I do this?
> Thanks for help!
>|||On Feb 16, 4:32 pm, "Aaron Bertrand [SQL Server MVP]"
<ten...@.dnartreb.noraa> wrote:
> SELECT MAX(date_column) FROM table
> <superb...@.gmail.com> wrote in message
> news:1171639291.878469.56900@.m58g2000cwm.googlegroups.com...
>
> >I have 3 different dates from same table same coloumn. I want to
> > compare these 3 dates and find out the latest date. How can I do this?
> > Thanks for help!- Hide quoted text -
> - Show quoted text -
Thank you very much!, but I need to update this max(date_coloumn) to
one of coloumn in another table. So I write like this:
update compnay
set datefield3 = max(a.freedateField_02)
inner join aTabel on aTable.customerID=compnayID and aTable.type in
(200, 203, 205)
But It returns an error: An aggregate may not appear in the set list
of an UPDATE statement.
Sorry for my stupid question. I am really bad in SQL.|||> Thank you very much!, but I need to update this max(date_coloumn) to
> one of coloumn in another table. So I write like this:
> update compnay
> set datefield3 = max(a.freedateField_02)
> inner join aTabel on aTable.customerID=compnayID and aTable.type in
> (200, 203, 205)
> But It returns an error: An aggregate may not appear in the set list
> of an UPDATE statement.
> Sorry for my stupid question. I am really bad in SQL.
Why would you need to do this? Are you going to run this UPDATE statement
every time any row in aTabel changes? You can always get that MAX date from
a query, so I see absolutely no need to replicate it to another table every
time it changes. Just include that join in your queries or create a view
that does the same.
A|||On Feb 16, 5:27 pm, "Aaron Bertrand [SQL Server MVP]"
<ten...@.dnartreb.noraa> wrote:
> > Thank you very much!, but I need to update this max(date_coloumn) to
> > one of coloumn in another table. So I write like this:
> > update compnay
> > set datefield3 = max(a.freedateField_02)
> > inner join aTabel on aTable.customerID=compnayID and aTable.type in
> > (200, 203, 205)
> > But It returns an error: An aggregate may not appear in the set list
> > of an UPDATE statement.
> > Sorry for my stupid question. I am really bad in SQL.
> Why would you need to do this? Are you going to run this UPDATE statement
> every time any row in aTabel changes? You can always get that MAX date from
> a query, so I see absolutely no need to replicate it to another table every
> time it changes. Just include that join in your queries or create a view
> that does the same.
> A
Yes, I have a report which is hard coded to use the coloumn only from
table called Company. But the date inforamtion is stored into another
table (aTable). I actually need to schdeule it and run it
automatically.
In the aTable, there 3 different type records contains the different
date for the same company. I need to update the lastest date to the
Company table which has the same companyID in the aTable.CustomerID.|||> Yes, I have a report which is hard coded to use the coloumn only from
> table called Company.
Then I would suggest changing the report. Or creating a new one and using
that one instead.
> I actually need to schdeule it and run it automatically.
And it's okay if the report returns incorrect data in between your schedule?
A|||You cannot use an aggregate function on the LHS of the SET clause in an
UPDATE statement. As an alternative, you could try:
UPDATE Company
SET date3 = ( SELECT MAX( a1.freedate2 )
FROM atable a1
WHERE a1.CompanyId = Company.CompanyId
AND a1.type IN ( 200, 203, 205 ) )
WHERE EXISTS ( SELECT *
FROM atable a1
WHERE a1.CompanyId = Company.CompanyId
AND a1.type IN ( 200, 203, 205 ) ) ;
--
Anith|||On Feb 16, 7:54 pm, "Anith Sen" <a...@.bizdatasolutions.com> wrote:
> You cannot use an aggregate function on the LHS of the SET clause in an
> UPDATE statement. As an alternative, you could try:
> UPDATE Company
> SET date3 = ( SELECT MAX( a1.freedate2 )
> FROM atable a1
> WHERE a1.CompanyId = Company.CompanyId
> AND a1.type IN ( 200, 203, 205 ) )
> WHERE EXISTS ( SELECT *
> FROM atable a1
> WHERE a1.CompanyId = Company.CompanyId
> AND a1.type IN ( 200, 203, 205 ) ) ;
> --
> Anith
Thank you, it works very well.

how to compare 2 date by "month"?

I'm doing DTS, Here is one of my Sql Query in DTS

Select * From ZT_DailyRpt_Detail
Where
isNumeric(TenDayDate) = 1 And TenDayDate <
Convert(varchar(10),DateAdd(Month,-CAST
((SELECT keepmonth
FROM zt_databackup a, zt_biller b
WHERE a.companycode = b.companycode AND
zt_DailyRpt_Detail.biller_code = b.billercode) AS int),GetDate()),112)

the sub query 【SELECT keepmonth
FROM zt_databackup a, zt_biller b
WHERE a.companycode = b.companycode AND
zt_DailyRpt_Detail.biller_code = b.billercode) AS int】will return a value 6 or 12

for the reason, every month have differnet days, ( some have 31 days , some are 30 days ) I don't want to check the day of date , only to compare month

if sub query return "6" and I do DTS on 2007/07/29 , will select date whichTenDayDate< 2007/01 not TenDayDate<2007/01/29 ( don't want to check the day of date)

does my query correct? if not can you correct it for me? thank you very much

Not sure I understood your problem, but maybe what you're looking for isDATEDIFFsql function?

|||

sorry for not describe my question clearly

my problem is

if I want to compare 2 date for example one is 2007/01/22 another is 2007/07/30

2007/07/30 - 2007/01/22 = 2007/06/08 right? that is not what I need

I need the result is 2007/06

I want to do DTS

if user run DTS in 2007/07/28 , want to select the data < 2007/07/28- 6 months , so it would be where data < 2007/01/28

I am not select Data < 2007/01/28 , I want to select Data < 2007/01 ( need not to compare the Day )

thank you

Friday, February 24, 2012

How to combine two columns into one in an sql

I have an stored procedure that returns 3 columns. Month, Date, and Total Number of Calls.

Here is the stored Proc:

SELECTDATEPART(mm, CALLSTARTTIME) , DATEPART(dd, CALLSTARTTIME),COUNT(*)

FROMCALL_LOG_MASTER

WHERE(COMMERCIALS = '1')AND(PINCODEIS NOT NULL)

GROUP BY DATEPART(mm, CALLSTARTTIME),DATEPART(dd, CALLSTARTTIME)

ORDER BY DATEPART(mm, CALLSTARTTIME),DATEPART(dd, CALLSTARTTIME)

It returns a table:

MONTH DATE TOTAL NUMBER OF CALLS
======= ===== ===========
1 1 10

1 2 15

My question is: is it possible to combine the Month and Date column into one column. e.g.

Date Total Number of Calls
==== ==============
1/1 10
1/2 15

Please Help, Thanks in advance :)

SELECT CONVERT(nvarchar(2),DATEPART(mm, CALLSTARTTIME)) + '/' + CONVERT(nvarchar(2),DATEPART(dd, CALLSTARTTIME)) AS [Date],COUNT(*)

FROMCALL_LOG_MASTER

WHERE(COMMERCIALS = '1')AND(PINCODEIS NOT NULL)

GROUP BY DATEPART(mm, CALLSTARTTIME)) + '/' + CONVERT(nvarchar(2),DATEPART(dd, CALLSTARTTIME))

ORDER BY DATEPART(mm, CALLSTARTTIME),DATEPART(dd, CALLSTARTTIME)

|||

thx, I did some configuration. works like a charm

SELECT CONVERT(nvarchar(2),DATEPART(mm, CALLSTARTTIME)) + '/' +CONVERT(nvarchar(2),DATEPART(dd, CALLSTARTTIME))AS[Date],COUNT(*)

FROMCALL_LOG_MASTER

WHERE(COMMERCIALS = '1')AND(PINCODEIS NOT NULL)

GROUP BY DATEPART(mm, CALLSTARTTIME) ,DatePart(dd, Callstarttime),CONVERT(nvarchar(2),DATEPART(mm, CALLSTARTTIME)) + '/' +CONVERT(nvarchar(2),DATEPART(dd, CALLSTARTTIME))

ORDER BY DATEPART(mm, CALLSTARTTIME),DATEPART(dd, CALLSTARTTIME)

How to combine Multiple Dataset result in each row of the report

Hi,

I need to produce a report in MS SQL Server Reporting Service 2005 which has some date fields & need to pass these date fields to find out the no_of_User on that date from another database. For example

Itemid

Availabilty_Start_Dt

Availabilty_End_Dt

User_On_St_DT (this info is in another DB & need to pass Availabilty_Start_Dt )

User_On_ED_DT (this info is in another DB & need to pass Availabilty_Start_Dt )

I am facing two problem here. Since hereis two different dataset needed how can I combine the dataset result to produce each row of the report.

REally appreciate if anyone can show me some light on it.

Regards,

write a strored procedure in the backend and try to write the two queries and combine the results and store in a temp table.

use the stored procedure in the reporting services. Backend is the best solution for it.