Createtable#tmp(uuidint,cNamenvarchar(50)) |
insertinto#tmpvalues(1,'蘋果') |
insertinto#tmpvalues(2,'葡萄') |
insertinto#tmpvalues(1,'蘋果111') |
insertinto#tmpvalues(2,'葡萄111') |
insertinto#tmpvalues(1,'蘋果222') |
insertinto#tmpvalues(3,'橘子') |
--查詢 |
Select*from#tmp |
--將結(jié)果拼接在一起 |
Selectx.uuid,left(cName,len(cName)-1)ascName |
from ( |
Selectuuid |
,(SelectcName+','from#tmpwhereuuid=t1.uuidforxmlpath(''))ascName |
from#tmpast1 |
groupbyuuid |
)x |
ps: 在 SQL SERVER 中只有用 for xml 的寫法才能實(shí)現(xiàn)該功能。 |
|
--添加記錄 |
insertinto[dbo].[T_BU_STOCK] |
([STORAGE_YEAR],[STORAGE_MONTH],[STORAGE_DAY],[STORAGE_DATE],[VEHICLE_BELONG],[CAR_SERIES_CODE]) |
Values('2015','7','22','2015-07-22','1','CR-V') |
|
--添加記錄 |
insertinto#T_BU_STOCK |
([STORAGE_YEAR],[STORAGE_MONTH],[STORAGE_DAY],[STORAGE_DATE],[VEHICLE_BELONG],[CAR_SERIES_CODE]) |
Select 2015,7,22,'2015-07-22','1','CR-V' |
|
--查詢表的結(jié)果 |
insertinto#T_BU_STOCK |
([STORAGE_YEAR],[STORAGE_MONTH],[STORAGE_DAY],[STORAGE_DATE],[VEHICLE_BELONG],[CAR_SERIES_CODE]) |
Select 2015,7,22,'2015-07-22','1','CR-V' |
from#T_BU_STOCK |
|
--執(zhí)行存儲(chǔ)過(guò)程方式(存儲(chǔ)過(guò)程返回的值必須要和添加表的列值結(jié)果一致) |
insertinto#T_BU_STOCK |
EXECPdd_Stock |
|
--備份表 |
Select*intoT_BU_DLR_2015_08_20fromT_BU_DLR |
--創(chuàng)建臨時(shí)表 |
Select*into#T_BU_DLR_2015_08_20fromT_BU_DLR |