Morning,I have a function I wrote to update a table. I looked at the table structure and made sure the values of the declares were as same as the table I'm trying to update. Declare @CreateDBName varchar(100), @Date varchar(100), @startOrder int, @startDate datetime, @endDate datetime, @desc varchar(50), @Sql varchar(MAX);SELECT @Date= CAST(YEAR(DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+2,0))) AS VARCHAR(4)) + left(CONVERT(char(20),DATEADD(MONTH,+1,GETDATE()),101),2)select @startDate = DATEADD(s,0,DATEADD(mm, DATEDIFF(m,0,getdate())+1,0)) select @endDate = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+2,0))select @desc = datename(month,CONVERT(char(20),DATEADD(MONTH,+1,GETDATE()),101))+' '+CAST(YEAR(DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+2,0))) AS VARCHAR(4))+' Month End'select @startOrder = convert(int,MAX(startorder)+1) from JB_Warehouse.dbo.DBOrder where StartOrder < 200SET @CreateDBName='P'+@Dateprint @CreateDBNameprint @startDateprint @endDateprint @startOrderprint @desc SET @Sql='INSERT INTO DBOrder VALUES (' + @CreateDBName + ', ' + @startOrder+ ', ' + @desc+ ', ' + @startDate+ ', ' + @endDate+ ', ''Y'')' execute (@sql)When I run this script this is what I get:P201101Jan 1 2011 12:00AMJan 31 2011 11:59PM45January 2011 Month EndMsg 245, Level 16, State 1, Line 29Conversion failed when converting the varchar value 'INSERT INTO DBOrder VALUES (P201101, ' to data type int.
Even though I converted the @startOrder variable to INT it still doesn't work. Any thoughts would be great. Thanks so much.Laura