Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic SQL in stored procedure - concatenate with multiple columns
    primarykey
    data
    text
    <p>I am trying to create a view with columns being concatenated to produce the rows for an import.</p> <p>Here is the statement I have :</p> <pre><code>SET NOCOUNT ON; declare @SQL as varchar(4000) --@CD as date --set @CD = convert(varchar(30), cast(getdate() as date), 110) -- Insert statements for procedure here set @SQL = 'CREATE VIEW vw_GCS_Export As select division, [primary image id],[Item Number], [Brand Name],[Marketing Description], [Colours]as Colors,[Live Date],[Sample Type],substring([FileName],charindex('+ CHAR(39) + '_' + CHAR(39) +',[FileName],1)+1,CHARINDEX('+ CHAR(39) + '.' + CHAR(39) +',[FileName],1)-5) as BatchID, '+ CHAR(39) + '670' + CHAR(39) +' as Status, [Primary image ID] + '+ CHAR(39) + '_P' + CHAR(39) +' as [Shot Name], Cast(Null as varchar(50))as [Swatch/Variation],Cast(Null as varchar(50))as [Alternate Shot],[UserName],''' + CAST(convert(date,Sysdatetime(),110)as varchar(10)) + ''' as [Import Date], Cast(Null as varchar(50))as [Return Instructions],Cast(Null as varchar(50))as [Rush Request], DATEADD(WEEKDAY,-5,[live date]) as [ImageDeliveryDate], '+ CHAR(39) + 'Division '+ CHAR(39) + '+ [division] +'+ CHAR(39) + ' * ' + CHAR(39) +' + [UserName] as JobName from Sheet1$' EXEC (@SQL) select * from vw_GCS_Export END </code></pre> <p>When I execute the stored procedure I get an error:</p> <blockquote> <p>Error converting data type varchar to float.</p> </blockquote> <p>Do I need to define the column as <code>nvarchar(50)</code> or something similar using cast?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload