SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Conversion failed when converting the nvarchar val
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

micnie_2020
Posting Yak Master

Malaysia
226 Posts

Posted - 11/29/2012 :  06:13:33  Show Profile  Reply with Quote
declare @i int
declare @val nvarchar(30)
declare @sSQL nvarchar(4000)
set @i=2
set @val='Test'
set @sSQL=N'insert into pivottbl'+@val+'(Dates)select replace(convert(varchar, cast(DateAdd(m,'+@i+'-1,''15/09/2012'') as date), 113),'' '',''/'') '
exec sp_executesql @sSQL

madhivanan
Premature Yak Congratulator

India
22765 Posts

Posted - 11/29/2012 :  06:19:21  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote


declare @i int
declare @val nvarchar(30)
declare @sSQL nvarchar(4000)
set @i=2
set @val='Test'
set @sSQL=N'insert into pivottbl'+@val+'(Dates)select replace(convert(varchar, cast(DateAdd(m,'+cast(@i as varchar(10))+'-1,''15/09/2012'') as date), 113),'' '',''/'') '
exec sp_executesql @sSQL

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000