-2

enter image description here

I Have temp table name @Definition which have 2 columns one for id and Field value I Have to take all rows in the field value as string in @P_Output

declare @P_Output varchar(500);
set @P_Output=(select case when (ISNumeric(FieldValue))=1 then convert(varchar(100),FieldValue) else FieldValue END from @Definition)

This give my an error :

Conversion failed when converting the varchar value 'You get an Error in line ' to data type int.

my table look like the picture and the required output needed to be :

P_Output=create table (id int not null identity(1,1).......
  • 1
    Please provide sample input data and the expected output – Scott Hodgin Nov 27 '16 at 12:52
2

You should be able to customize this example:

set nocount on
Declare @Definition table (ID int, FieldValue varchar(100))
DECLARE @P_Output varchar(max)

insert into @Definition (ID,FieldValue) values(1,'CREATE TABLE dbo.test')
insert into @Definition (ID,FieldValue) values(2,'(')
insert into @Definition (ID,FieldValue) values(3,'col1 int')
insert into @Definition (ID,FieldValue) values(4,')')

SELECT @P_Output = isnull(@P_Output + '', '') + FieldValue
from @Definition order by ID

print @P_Output

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.