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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

micnie_2020
Posting Yak Master

Malaysia
232 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
22864 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  
 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.14 seconds. Powered By: Snitz Forums 2000