.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> SQL Query >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Different SQL commands in Action

Posted By:Abhisek Panda       Posted Date: November 25, 2009    Points: 10    Category: SQL Query    URL: http://www.dotnetspark.com  
 

     Different SQL commands in Action



      This script file contains simple sql commands. It include commands to create a database, create a table, inserting values to table, changing column of a table. It also demonstrates the use of some functions such as power, abs, datepart, date diff, min substring.

It will be useful for newcomers to sql.

create database itm
create table itm(name varchar(20),roll int,mark int,phoneno char(10))
insert itm values('lipu',41,77,9861205901)
alter table itm alter column phoneno char(10)
sp_help itm
select*from itm
insert itm (roll,mark)values(108,78)
update itm set name='abhi' where roll=108
select name,roll from itm where mark=78
select substring('lipunmqwer',5,3)
select abs (12)
select power(2,3)
select min(mark)from itm
select datepart(yy,getdate())
select datediff(yy,'2005-07-12','2008-07-12')
Descriptin of commands:-

power(a,b) - calculates a^b

abs() - shows the absolute value

min(values) - selects minimum of a given range of values

substring(string,start,end) - extract the substring according to the range passed as start and end from the given string

getdate() - it will show the current date

datepart(parameter,date) - will extract the date part according to the parameter passed. The parameters can be yy for year, mm for month or dd for date.

datediff(parameter,date1,date2) - will extract the difference between two given dates as per the parameter passed.

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend