December 31, 2013 at 2:26 am
create table estr
(
custo int,
product varchar(20),
val int,
billed_date datetime
)
insert into estr(custo,product,billed_date,value) values('10','Milk','2013-04-11','2000')
insert into estr(custo,product,billed_date,value) values('10','Milk','2013-04-21','500')
insert into estr(custo,product,billed_date,value) values('10','Milk','2013-05-05','100')
insert into estr(custo,product,billed_date,value) values('10','Milk','2013-05-11','2000')
insert into estr(custo,product,billed_date,value) values('10','fruits','2013-05-11','500')
insert into estr(custo,product,billed_date,value) values('30','fruits','2013-04-11','2000')
insert into estr(custo,product,billed_date,value) values('30','fruits','2013-05-11','1000')
from here i wanna extract the month with year for counting purpose how ll do ?
guide me?
December 31, 2013 at 2:31 am
Share your expected output as well for better understanding.
December 31, 2013 at 2:37 am
custoproductvalno.of.mon
10Friut 1300 1
10Milk 2900 2
30Milk 6000 2
i wanna calculate no.of.months along with year ?
December 31, 2013 at 2:50 am
raghuldrag (12/31/2013)
custoproductvalno.of.mon10Friut 1300 1
10Milk 2900 2
30Milk 6000 2
i wanna calculate no.of.months along with year ?
what representation for 'no.of.mon' column ? need more details
December 31, 2013 at 2:55 am
Split thread. Please post replies to the original thread here, where you will obtain background information and progress to date.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
December 31, 2013 at 3:02 am
i need the output like
for example 2013-04-01 is in table my expectation output is 04-2013 (extract month with year)......
December 31, 2013 at 11:36 am
raghuldrag (12/31/2013)
i need the output likefor example 2013-04-01 is in table my expectation output is 04-2013 (extract month with year)......
Hi.
This seems to be a relatively simple single SELECT statement.
Please use DATEPART to convert billed_date into a year with yyyy, and a second datepart to get the month with mm.
Then group your query the way you need to summarize the data, using SUM to add up values.
Thanks
John.
December 31, 2013 at 6:15 pm
Assuming this is still true: billed_date datetime
right('0' + cast(month(billed_date) as varchar(2)),2) + '-' + cast(year(billed_date) as varchar(4))
December 31, 2013 at 6:17 pm
Now, I have a suggestion. You should get to know Books Online. In SSMS press Shift-F1. There is a lot of good information in there and you don't have to rely on waiting for volunteers to answer all your questions. If something doesn't make sense there, come ask questions here.
December 31, 2013 at 10:13 pm
Lynn Pettis (12/31/2013)
Assuming this is still true: billed_date datetimeright('0' + cast(month(billed_date) as varchar(2)),2) + '-' + cast(year(billed_date) as varchar(4))
... or...
SELECT RIGHT(CONVERT(CHAR(10),GETDATE(),105),7)
--Jeff Moden
Change is inevitable... Change for the better is not.
January 1, 2014 at 8:09 am
Jeff Moden (12/31/2013)
Lynn Pettis (12/31/2013)
Assuming this is still true: billed_date datetimeright('0' + cast(month(billed_date) as varchar(2)),2) + '-' + cast(year(billed_date) as varchar(4))
... or...
SELECT RIGHT(CONVERT(CHAR(10),GETDATE(),105),7)
To the OP: And you can learn about COVERT and the different format codes it accepts by reading Books Online as well.
Remember, Books Online can be your friend.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply