Add Calculated Age Column in SQL Server through Query
Alter table Child_Record
Add Age AS (datediff(year,[BirthDate],getdate() ))
Trim Leading (First) Charcter - TSQL Query
Trim Leading (First) Character in T-SQL Query using Left, Right, Len Function
Select N, LEFT(RIGHT(N, len(N)-1),len(N)-1) as Number
From Number
Other Query
Select Name, stuff(Name, 1,1,'') Name from Contact
select Name, Substring(Name,2,8000) from Contact
Split One Column to Three Column - SQL Query
Split One Column like Full Name to First Name, Middle Name, Last Name
- Using CharIndex, Reverse, RTrim, Substring in TSQL
SELECT [Child Name],LEFT([Child Name],CHARINDEX(' ',[Child Name] + ' ')-1) AS First_Name,
Rtrim(substring([Child Name],CHARINDEX(' ',[Child Name],0)+1,len([Child Name])-CHARINDEX(' ',[Child Name],0)+1-CHARINDEX(' ', REVERSE([Child Name])))) Middle_Name,
Right([Child Name],ISNULL(NULLIF(CHARINDEX(' ', REVERSE([Child Name])) - 1,-1), LEN([Child Name]))) AS Last_Name
From Child
Split One Column to 2 column - SQL Query
Split One Column to 2 column from comma separator using SUBSTRING, LEFT, LEN Functions
Select
[CorpGroupName],
[Div],
[Corps],
left([Corps], charindex(',', [Corps])-1) as City,
SUBSTRING([Corps], CHARINDEX(',', [Corps]) + 1, LEN([Corps])) as [State]
From [dbo].[Corp]
Select
[CorpGroupName],
[Div],
[Corps],
left([Corps], charindex(',', [Corps])-1) as City,
SUBSTRING([Corps], CHARINDEX(',', [Corps]) + 1, LEN([Corps])) as [State]
From [dbo].[Corp]
Subscribe to:
Posts (Atom)