Look at SELECT INTO
select *
into #TempTable
from SomeTale
select *
from #TempTable
SELECT ID as 'ID',
(SELECT <....> FROM table WHERE <...> ) AS 'Total No of people'
FROM somewhere
SELECT LTRIM(RTRIM(Names)) AS Names FROM Customer
SELECT CONVERT(varchar(10), field_name) FROM table_name
LEFT(colName, 1)firstname lastname
Bill smith
you can do something like
select firstname + ' ' + lastname from thetable
What I use for
IsNotNullOrEmptyOrWhiteSpace
in T-SQL is: linkSELECT [column_name] FROM [table_name]
WHERE LEN(RTRIM(ISNULL([column_name], ''))) > 0
Code
USE AdventureWorks2012;
GO
SELECT ProductNumber, Category =
CASE ProductLine
WHEN 'R' THEN 'Road'
WHEN 'M' THEN 'Mountain'
WHEN 'T' THEN 'Touring'
WHEN 'S' THEN 'Other sale items'
ELSE 'Not for sale'
END,
Name
FROM Production.Product
ORDER BY ProductNumber;
GO
UPDATE
MyTable
SET
MyColumn = UPPER(MyColumn)
Finial save the result
LINK from stackoverflow
Use following syntax to create new table from old table in SQL server 2008 :
Select * into new_table from old_table
Adding Column in existing Table:
ALTER TABLE Tb_Table1 ADD isdone BIT DEFAULT 0
a BIT
column can have two values (0 = false, 1 = true) or no value at all (NULL)
Better techniques for trimming leading zeros in SQL Server?
I've been using this for some time:
SUBSTRING(str_col, PATINDEX('%[^0]%', str_col), LEN(str_col))
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。