Database Programming in SQL Server – SQL Server Tutorial

Database Programming in SQL Server :-

  • To do database programming SQL statements must be embedded in TSQL block.
  • The following SQL statements can be embedded in TSQL block.

(I) All DML commands

(II) All TCL commands

(III) DRL command

  • Syntax of the select statement:

Select @ var1=col1, @var2=col2 ——– from <tabname> [where<condition>]

Example   :    Select @ eno=empno, @ename=ename from emp where empno=7369

                              Select @sal=sal from emp where,empno=@eno

                              Print  ‘employee earning’ +cast (@sal as varchar)

Write a program to input an employee number & calculate the employee experience.

                    Declare  @eno int,@doj datetime

                    Declare @ expr int

                    Set @ eno =7566

                    Select @doj=hiredate from emp where empno=@eno

                    Set @expr=abs (datediff(yy,setdate() ,@doj))

                   Print ‘employee working since ‘+ cast(@expr as varchar)+’years’

                   Output  → employee working since 28 years.

Leave a Reply

Your email address will not be published. Required fields are marked *