SQL Server : multiple inserts into temp table while creating a value for each different insert

Viewed 683

Pardon my code, I am still learning.

What I want to do is take several select statements and insert them into a single temp table. For each select statement I would like some sort of identification to know which select statement the data came from.

I have a crude idea below to use the case statement below.

Error:

Msg 8152, Level 16, State 14, Line 14
String or binary data would be truncated.

Code:

if object_id('tempdb..#PP') is not null 
     drop table #PP

SELECT 
    #Pr.*, 
    Case
       When TranID = TranID then 'BK Problem'
       Else 'Error' End as 'Test'
INTO #PP
FROM #Pr
WHERE TypeID = 't'

--CCA Test
INSERT INTO #PP
    SELECT 
        #Pr.*, 
        Case
           When TranID = TranID then 'CCA Problem'
           Else 'Error' End as 'Test'
    FROM #Pr
    WHERE TypeID = 'r'

I appreciate any help pointing me in the right direction.

Thanks

2 Answers
Related