Common SQL statements (1)

Source: Internet
Author: User
Tags uuid

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


Common SQL statements (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.