Create temp table with column names from another tables column data
By : user3762886
Date : March 29 2020, 07:55 AM
seems to work fine Don't think its possible to return data the way I would like so ended up doing doing it with 2 DataTables.
|
Create Table Variable (or Temp Table) from an existing Table but with an Extra Column
By : Shawn
Date : March 29 2020, 07:55 AM
This might help you I want to create a table variable or temporary table, using data from another table but with an extra column. , Its simpler code :
SELECT *, cast('hbkkj' as nvarchar(100)) as New_Column
INTO #TempTable
FROM Existing_Table
WHERE Section = 2
|
How to insert data from single column of a temp table into multiple columns of main table?
By : alimad2
Date : March 29 2020, 07:55 AM
Does that help I have a data like showed below in temp table: , Try this: code :
INSERT INTO [dbo].[t_Act]
SELECT MAX(CASE WHEN D.RN=1 THEN D.Col END)[EventType]
,MAX(CASE WHEN D.RN=2 THEN D.Col END) [ClientMsgID]
,MAX(CASE WHEN D.RN=3 THEN D.Col END) [SessionID]
,MAX(CASE WHEN D.RN=4 THEN D.Col END) [Protocol]
,MAX(CASE WHEN D.RN=5 THEN D.Col END) [MessageType]
,MAX(CASE WHEN D.RN=6 THEN D.Col END) [SequenceNumber]
FROM(
SELECT *
,ROW_NUMBER() OVER(ORDER BY (SELECT NULL))RN
FROM #TempTable
)D
ROW_NUMBER() OVER(ORDER BY OrderColumn)RN
ROW_NUMBER() OVER(ORDER BY (SELECT NULL))RN
|
Adding column with default values to temp table when using two stored procedures to populate the temp table
By : user3184038
Date : March 29 2020, 07:55 AM
I wish this helpful for you I have a stored procedure that executes two stored procedures and gets the correct data, but now I need to add a column into the temp table with default values. , create the temp table with the new column with default value as 2 code :
CREATE TABLE #tmp
(
ID INT IDENTITY(1,1) ,
CODE nvarchar(50),
Description nvarchar(50),
LocationType INT default 2
)
INSERT INTO #tmp (CODE, Description)
EXECUTE dbo.uspStockAdjustmentWorkCentreSelectAll
UPDATE #tmp
SET LocationType = 1
INSERT INTO #tmp (CODE, Description)
EXECUTE dbo.uspStockAdjustmentGetSAPStorageType
|
insert data in physical table from temp table with less column
By : Maxim Lobanov
Date : March 29 2020, 07:55 AM
may help you . I have one issue, I'm not too sure is it possible by anyway or not.
|