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
 conversion failed

Author  Topic 

kshitizgp
Starting Member

31 Posts

Posted - 2012-01-13 : 00:33:16

declare @public_holidays int

select sum(counter)
from
('SELECT count(HolidayDate) as counter FROM Efiling.dbo.tblHoliday_Master where HolidayDate between ''01-01-2012'' and ''01-02-2012'' group by HolidayDate') AS a

set @public_holidays = 'select sum(counter)
from
(''SELECT count(HolidayDate) as counter FROM Efiling.dbo.tblHoliday_Master where HolidayDate between '''''+CONVERT(nvarchar(30), @start_Date, 110) +''''' and '''''+CONVERT(varchar(30),@end_Date, 110) +''''' group by HolidayDate'') AS a '
@public_holidays

kshitizgp
Starting Member

31 Posts

Posted - 2012-01-13 : 00:37:07
onversion failed when converting the nvarchar value 'select sum(counter)
from
('SELECT count(HolidayDate) as counter FROM Efiling.dbo.tblHoliday_Master where HolidayDate between ''01-01-2012'' and ''01-02-2012'' group by HolidayDate') AS a ' to data type int.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-13 : 04:01:02
you've declared @public_holidays as int and trying to assign a string value to it which is why the error. Please change it to correct data type and it will work

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -