July 24, 2012 at 10:40 pm
hi friends,
In my sp ve the date of " where date between'01-apr-2011' and '30-apr-2011' " for #temp,
again i need to calculate the values of date in '01-apr-2010' and '30-apr-2010' for #temp1
how to make the query....
July 24, 2012 at 11:58 pm
Can you explain bit more on your doubt?
Regards,
Karthik.
SQL Developer.
July 25, 2012 at 12:14 am
if suppose em calculting 'o1-apr-2011' and '30-apr-2011'..... wanna the data also perivous year of same month.... and display month column separately
July 25, 2012 at 12:41 am
raghuldrag (7/25/2012)
if suppose em calculting 'o1-apr-2011' and '30-apr-2011'..... wanna the data also perivous year of same month.... and display month column separately
I sincerely feel you are wasting time( including yours ) in this forum now
You never give the data we ask for to help you, you never heed to advice of not using SMS language and you never give enough details to help you either
If you really need some help from this forum, change your posting behavior otherwise you are simply wasting your time IMHO.
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
July 25, 2012 at 12:45 am
thks for your given comments
July 25, 2012 at 1:58 am
account trans date amount
============================
E909 cr 01apr11 8000
E303 dr 03mar09 900 ==> actaul table
R579 cr 01jan11 900
R954 dr 04jun 01 7000
credit
(amountcolumn)=cr,
dedit(amountcolumn)=dr
now i need to split the table credit,debit, month........
MY QUERY:
==========
select
account,
extract(month from fs_tran_date) as mon_name,
debit=
sum(
case trans
when 'Dr' then amount else 0 end)
credit=
sum(
case trans
when 'Cr' then amount else 0 end)
from
@table
where date between'01-apr-2011'and '05-apr-2011'
and left(account,1) in ('E','R')
group by
account
now the problem is while i am using Extract its shoeing error..... any one can help me
account trans credit debit mon_name
=================================
E909 cr 8000 0000 APR
E303 dr 0000 900 MAR ==> Expectingoutput table
R579 cr 900 0000 JAN
R954 dr 00000 7000 JUN
July 25, 2012 at 2:00 am
Google DATEADD
DATEADD(YEAR,-1,GETDATE())
Also dont use string litterals for dates, use the an ISO date format like YYYY-MM-DDTHH:MM:SS.ms
July 25, 2012 at 2:25 am
how can split month coumn from date...would please give me brief
July 25, 2012 at 2:26 am
Google "DATE functions in T-SQL"
July 25, 2012 at 3:24 am
hi ,
I'm created procedure but doesnt given the expecting ouput,show sum errors
MYQUERY:
=========
CREATEprocedure PP__POSTINGS
(
@x datetime,
@y datetime
)
as
begin
select
account
DATEADD(month,0,@x) as PR_MONS,
debit=
sum(
case trans
when 'Dr' then amount else 0 end)
into #templ
from
@table
where date between @x and @y
and left(account1) in ('E','R')
group by
fs_account_no
select
account
DATEADD(month,0,@y) as PR_MONS,
credit=
sum(
case trans
when 'Cr' then amount else 0 end)
into #tempt
from
@table
where date between @x and @y
and left(account1) in ('E','R')
group by
account
select
x.account
x.PR_MONS,
x.debit,
y.credit,
closin_Bal=
(
case when left(account1) in ('E') then x.debit-y.credit
when left(account1) in ('R') then -x.debit+y.credit
else 0
end
)
from
#templ x(nolock)
left outer join
#tempt y(nolock)
on
x.account=y.account
end
/* exec PP__POSTINGS
'01-apr-2011','30-apr-2011'*/
July 25, 2012 at 3:26 am
Did you google "DATE functions in T-SQL"
If so the first link would take you through all the different date functions that exist in SQL and you would of found the two functions you require to just get the month datepart[/b] from a date column.
July 25, 2012 at 3:35 am
ya google it, was my query is correct or not???
July 25, 2012 at 3:38 am
No, your using the wrong date function, your adding to a date instead of getting the part of the date you want.
The clues are in the bold italic text of my previous post.
July 25, 2012 at 6:06 am
hi friend.
when i am using DATEPART() its shows the month number(april,4),But i need the month name..... while i m using DATENAME() function giving the same month number only in my procedure....not showing the name
Help me
July 25, 2012 at 6:38 am
raghuldrag (7/25/2012)
hi friend.when i am using DATEPART() its shows the month number(april,4),But i need the month name..... while i m using DATENAME() function giving the same month number only in my procedure....not showing the name
Help me
What does the below code return in your system?
SELECT DATENAME(MONTH, CURRENT_TIMESTAMP)
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply