Yes, when both the datatypes in the where clause are of datatype varchar your result set could be messy.
What does this get you?
select convert(datetime, convert(varchar, month(SQLTranDate)) + '/01/'
+ convert(varchar, year(SQLTranDate))) as Year,
sum(SQLTranAmt)...
The Year field actually has date format so would see something like '2006-02-01 00:00:00.000' (one record per each month-year combination.
Isn't this the output you expected?
Year Total
2006-02-01 00:00:00.000 93
2006-03-01 00:00:00.000 1679
2006-04-01...
lannym,
Can you post the query you are running? You should not get data older than 12 months with the query I posted so not sure how you are getting 2005 data.
Also, the only month you would see twice in the output would be feb because I did not filter current month. Do you want that filtered...
lannym,
This definitely is not the most elegant solution but should work.
select month([SQLTranDate]) as Month,
year(SQLTranDate]) as Year,
sum([SQLTranAmt]) as Total
FROM chart1
where [SQLTranDate] >= convert(varchar(10), dateadd(day, -day(getdate()) + 1, dateadd(month, -12...
UNCMoochie,
Your code was correct, but order of the conditions in the case statement was wrong.
<b>
update #T1 set yr_joined =
case
when s98 > 0 then '1998'
when s99 > 0 then '1999'
when s00 > 0 then '2000'
end
</b>
Best Regards,
AA
There are several ways to do this. One such idea would be:
SELECT call_number,
History,
Current_Group
FROM #TableA a,
(SELECT call_number,
MAX(History) max_history
FROM #TableA
GROUP BY call_number) b
WHERE a.call_number = b.call_number
and a.history = b.max_history...
How about something like this?
select acct,
dates,
att
from DTWDTA.DWFLTH1 a
where dates in (select top 5
b.dates
from DTWDTA.DWFLTH1 b
where a.acct = b.acct...
I would suggest to avoid cursors whenever possible.
Here is a snippet to get you started:
create table #Test (Name varchar(10), Id int)
insert into #Test values ('a', 1)
insert into #Test values ('b', 4)
insert into #Test values ('c', 5)
insert into #Test values ('d', 8)
insert into #Test...
Try the following:
Drop the primary key constraint.
Alter the data type of the column as desired.
Add the primary key constraint back.
Best Regards,
AA
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.