Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 converting varchar to tinyint

Author  Topic 

tariq2
Posting Yak Master

125 Posts

Posted - 2011-10-26 : 09:15:33
Hi,
Thank you in advance for your assistance.
MonthNum is tinyint and therefore the statement
below yields
'
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'Total' to data type tinyint.'



select username,isNULL(monthnum,'Total')



,reportname, sum(reportcount) from View_BIUsers_ReportData where TerritoryName = 'Germany'
and Year = '2011' and TreeYear = '2011'
group by username,monthnum,reportname
with rollup

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-10-26 : 09:20:39
select username,isNULL(convert(varchar(10),monthnum),'Total')


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-10-26 : 09:39:07
GROUP BY WITH ROLLUP?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

tariq2
Posting Yak Master

125 Posts

Posted - 2011-10-26 : 09:39:35
Worked a treat Nigel :)
thank you
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-10-27 : 09:27:55
This should be done in your front end application unless you export data to text file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -