insert into table1 (field1, field2)
select fieldA, fieldB table2 where 條件
select type
when 'a' then '1'
when 'b' then '2'
end
select table
update [DB1].[dbo].table1
set [DB1].[dbo].table1.Name = b.Name
from [DB1].[dbo].table1
join DB2.[dbo].table2 as b on [DB1].[dbo].table1.ID = b.ID
select a.field1+b.field1 as c
from [DB].[dbo].[Table1] as a
join [DB].[dbo].[Table1] as b on 1=1
where a.index = 70 and b.index = 1321
select * from person.StateProvince where CountryRegionCode in
(select CountryRegionCode from person.CountryRegion where Name like 'C%')
declare @t table(CountryRegionCode nvarchar(3))
insert into @t(CountryRegionCode) (select CountryRegionCode from person.CountryRegion where Name like 'C%')
select * from person.StateProvince where CountryRegionCode in (select * from @t)
SELECT
c.name 'Column Name',
t.Name 'Data type',
c.max_length 'Max Length',
c.precision ,
c.scale ,
c.is_nullable,
ISNULL(i.is_primary_key, 0) 'Primary Key'
FROM
sys.columns c
INNER JOIN
sys.types t ON c.user_type_id = t.user_type_id
LEFT OUTER JOIN
sys.index_columns ic ON ic.object_id = c.object_id AND ic.column_id = c.column_id
LEFT OUTER JOIN
sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id
WHERE
c.object_id = OBJECT_ID('Comm_Account')