In this article I am listing some basic and very important Sql queries which we use in our daily development tasks as Database Administrator or as Front-End Developer.
1. Sql Query to Select Day from Given Date:
Query:
select DAY('2014-02-07 11:48:48.020') as DAYOFDATE
Output:
2. Sql Query to Select Month from Given Date:
Query:
Select MONTH('2014-02-07 11:48:48.020') as MonthOfDate
Output:
3. Sql Query to get Year from Given Date:
Query:
7. Sql Query to Get the length of the Column in a table:
Query:
1. Sql Query to Select Day from Given Date:
Query:
select DAY('2014-02-07 11:48:48.020') as DAYOFDATE
Output:
2. Sql Query to Select Month from Given Date:
Query:
Select MONTH('2014-02-07 11:48:48.020') as MonthOfDate
Output:
3. Sql Query to get Year from Given Date:
Query:
select YEAR('2014-02-07 11:48:48.020')
as YearofDate
Output:
4. Sql Query to Get the Length of String or Text
Query:
Select DATALENGTH('Name') as LegthofName
Output:
5. Sql Query to get the version of Sql Server Installed:
Query:
Select @@VERSION As
SQLVERSIONInstalled
Output:
6. Sql Query to Get Position(Index) of a character in a String:
Query:
Select CHARINDEX('a','bd,ab,cd') AS CharacterIndex
Here in this query a is the character whose index is to be found in thee string 'bd,ab,cd'
Output:
7. Sql Query to Get the length of the Column in a table:
Query:
Select COL_LENGTH('name of table','column name')As LengthofColumn
8. Sql Query to select the random records from a table:
Query:
Select * from name_of_table order
by NEWID()
9. Sql Query to select specific number of character from the Right Side of String:
Query:
Query:
Select RIGHT('this is test',9) as textFromRight
Output:
0 comments:
Post a Comment