Createtable#tmp(uuidint,cNamenvarchar ()) |
Insert INTO#tmpvalues(1,' Apple ') |
Insert INTO#tmpvalues(2,' grapes ') |
Insert INTO#tmpvalues(1,' Apple 111 ' ) |
Insert INTO#tmpvalues(2,' grapes 111 ') |
Insert INTO#tmpvalues(1,' Apple 222 ') |
Insert INTO#tmpvalues(3,' Orange ') |
-- Query |
Select*from#tmp |
-- stitching the results together |
Selectx. UUID , left (cname,len(CNAME)-1 )ascName |
From ( |
SelectUUID |
, (SelectcName+', 'from#tmpwhereuuid =T1. UUID for XML Path (')) as CName |
From#tmpast1 |
Groupbyuuid |
)x |
PS: This function can only be implemented in SQL SERVER using the FOR XML notation. |
|
-- Add record |
Insertinto[dbo]. [T_bu_stock] |
([storage_year],[storage_month], [storage_day],[ Storage_date],[Vehicle_belong],[Car_series_code]) |
Values('a ',' 7 ','a ',' 2015-07-22 ',' 1',' cr-V ') |
|
-- Add record |
Insertinto#T_BU_STOCK |
([storage_year],[storage_month], [storage_day],[ Storage_date],[Vehicle_belong],[Car_series_code]) |
Select , 7,' 2015-07-22 ' ,' 1 ',' cr-V ' |
|
-- Query the results of the table |
Insertinto#T_BU_STOCK |
([storage_year],[storage_month], [storage_day],[ Storage_date],[Vehicle_belong],[Car_series_code]) |
Select , 7,' 2015-07-22 ' ,' 1 ',' cr-V ' |
From#T_BU_STOCK |
|
-- Execute stored procedure ( The value returned by the stored procedure must be the same as the column value result of the added table ) |
Insertinto#T_BU_STOCK |
EXECPdd_stock |
|
-- Backup table |
Select*intot_bu_dlr_2015_08_20fromt_bu_dlr |
-- Create a temporary table |
Select*to#T_BU_DLR_2015_08_20fromt_bu_dlr |