常用SQL语句(1)

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
--将结果拼接在一起
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  的写法才能实现该功能。

--添加记录
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'

--查询表的结果
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

--执行存储过程方式(存储过程返回的值必须要和添加表的列值结果一致)
insertinto#T_BU_STOCK
EXECPdd_Stock

--备份表
Select*intoT_BU_DLR_2015_08_20fromT_BU_DLR 
--创建临时表
Select*into#T_BU_DLR_2015_08_20fromT_BU_DLR 

网页名称:常用SQL语句(1)
分享网址:http://www.hxwzsj.com/article/igjcgp.html

其他资讯

Copyright © 2025 青羊区翔捷宏鑫字牌设计制作工作室(个体工商户) All Rights Reserved 蜀ICP备2025123194号-14
友情链接: 手机网站建设 移动手机网站制作 成都网站设计 成都做网站建设公司 网站建设 网站设计 网站建设改版 高端网站设计推广 专业网站设计 成都网站设计 成都网站建设公司 重庆电商网站建设 成都网站制作 成都网站建设 成都网站建设 网站建设费用 高端网站设计 app网站建设 手机网站设计 阿坝网站设计 成都网站建设公司 成都网站制作