This document provides an overview of basic T-SQL programming concepts including declaring variables, IF/ELSE statements, WHILE loops, and CASE expressions. It defines local variables using DECLARE, demonstrates assigning values using SET and SELECT, and shows how to conditionally execute code blocks using IF and IF/ELSE statements. Examples are also provided for WHILE loops, including using the BREAK and CONTINUE keywords, and the syntax for simple and searched CASE expressions is described. Sample databases, tables, and data are included for examples.
PL/SQL is a procedural language designed specifically to embrace SQL statements within its syntax. PL/SQL program units are compiled by the Oracle Database server and stored inside the database.
PL/SQL is a procedural language designed specifically to embrace SQL statements within its syntax. PL/SQL program units are compiled by the Oracle Database server and stored inside the database.
Student information management system project report ii.pdfKamal Acharya
Our project explains about the student management. This project mainly explains the various actions related to student details. This project shows some ease in adding, editing and deleting the student details. It also provides a less time consuming process for viewing, adding, editing and deleting the marks of the students.
Water scarcity is the lack of fresh water resources to meet the standard water demand. There are two type of water scarcity. One is physical. The other is economic water scarcity.
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxR&R Consult
CFD analysis is incredibly effective at solving mysteries and improving the performance of complex systems!
Here's a great example: At a large natural gas-fired power plant, where they use waste heat to generate steam and energy, they were puzzled that their boiler wasn't producing as much steam as expected.
R&R and Tetra Engineering Group Inc. were asked to solve the issue with reduced steam production.
An inspection had shown that a significant amount of hot flue gas was bypassing the boiler tubes, where the heat was supposed to be transferred.
R&R Consult conducted a CFD analysis, which revealed that 6.3% of the flue gas was bypassing the boiler tubes without transferring heat. The analysis also showed that the flue gas was instead being directed along the sides of the boiler and between the modules that were supposed to capture the heat. This was the cause of the reduced performance.
Based on our results, Tetra Engineering installed covering plates to reduce the bypass flow. This improved the boiler's performance and increased electricity production.
It is always satisfying when we can help solve complex challenges like this. Do your systems also need a check-up or optimization? Give us a call!
Work done in cooperation with James Malloy and David Moelling from Tetra Engineering.
More examples of our work https://www.r-r-consult.dk/en/cases-en/
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)MdTanvirMahtab2
This presentation is about the working procedure of Shahjalal Fertilizer Company Limited (SFCL). A Govt. owned Company of Bangladesh Chemical Industries Corporation under Ministry of Industries.
Final project report on grocery store management system..pdfKamal Acharya
In today’s fast-changing business environment, it’s extremely important to be able to respond to client needs in the most effective and timely manner. If your customers wish to see your business online and have instant access to your products or services.
Online Grocery Store is an e-commerce website, which retails various grocery products. This project allows viewing various products available enables registered users to purchase desired products instantly using Paytm, UPI payment processor (Instant Pay) and also can place order by using Cash on Delivery (Pay Later) option. This project provides an easy access to Administrators and Managers to view orders placed using Pay Later and Instant Pay options.
In order to develop an e-commerce website, a number of Technologies must be studied and understood. These include multi-tiered architecture, server and client-side scripting techniques, implementation technologies, programming language (such as PHP, HTML, CSS, JavaScript) and MySQL relational databases. This is a project with the objective to develop a basic website where a consumer is provided with a shopping cart website and also to know about the technologies used to develop such a website.
This document will discuss each of the underlying technologies to create and implement an e- commerce website.
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...Amil Baba Dawood bangali
Contact with Dawood Bhai Just call on +92322-6382012 and we'll help you. We'll solve all your problems within 12 to 24 hours and with 101% guarantee and with astrology systematic. If you want to take any personal or professional advice then also you can call us on +92322-6382012 , ONLINE LOVE PROBLEM & Other all types of Daily Life Problem's.Then CALL or WHATSAPP us on +92322-6382012 and Get all these problems solutions here by Amil Baba DAWOOD BANGALI
#vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore#blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #blackmagicforlove #blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #Amilbabainuk #amilbabainspain #amilbabaindubai #Amilbabainnorway #amilbabainkrachi #amilbabainlahore #amilbabaingujranwalan #amilbabainislamabad
1. Basics of T-SQL programming
Declaring variables and Parameters
1
2. • A local variable is defined using the DECLARE statement.
• The name of the local variable needs to start with the @ symbol
as the first character of its name.
Example: DECLARE @Count INT
• More than one variable can be defined with a single DECLARE
statement with a comma
Example: DECLARE @Count INT, @X INT, @Y INT, @Z
• A local variable is initially assigned a NULL value.
• A value can be assigned to a local variable by using the SET or
SELECT statement.
• Using SET:-
DECLARE @Count INT
SET @Count = 1
• Using SELECT statement to initialize the value of a local
variable with the value returned from a select that fetch the total
number of rows in the customer table.
declare @rowcount int
select @rowcount=(selectcount(*)from customer
print @rowcount
2
3. • An example that returns all the Customers records in the sales
database where the customer’s address column is equal to ‘Bahir
Dar’
declare @myaddress varchar(50)
set @myaddress='bahir dar'
select*from customer where [address]=@myaddress
Example
declare @var1 int,@var2 float,@var3 int,@sum int
set @var1=10
set @var2=20
set @var3=30
set @sum=@var1+@var2+@var3
print @sum
N.B.you can also use select to assign and to
display
3
4. IF ... ELSE statement
• T-SQL has the IF statement to help with allowing different code to be
executed based on the results of a condition.
• Format one:
IF <condition> <then code to be executed >
• Format two:
IF <condition> <then code to be executed >
ELSE < else code to be executed >.
• If a block of code is used then it will need to be enclosed in a BEGIN
and END statement.
Declare @x int
set @x = 29
if @x = 29 print 'The number is 29'
if @x = 30 print 'The number is 30'
• Now the condition statement can also contain a SELECT statement.
• The SELECT statement will need to return value or set of values that
can be tested. 4
5. Example
if(selectcount(*)from customer)<20
print'Number of customer is less than 20’
• If a SELECT statement is used the statement needs to be enclosed in parentheses.
parentheses.
Example
if (select count(*) from Student
where fname like '[A-D]%') > 0
print 'A-D Students are Found ‘
Example
if db_name() = 'master'
begin
Print 'We are in the Master Database'
Print ‘ ’
Print 'So whatever code you execute must be done carefully'
End
else if db_name() = ‘Library'
begin
Print 'We are in the test Library database ’
Print 'So Enjoy' 5
6. •Suppose we want to determine whether to update or
add a record to the Customer table in the Sales
database.
if exists(select * from customer where
Customer_ID = 'C-150')
Print 'Need to update'
else
Print 'Need to add new record'
Example
if exists(select*from customer
where customer_id='c-100')
print'record is found'
else
print'record is not found'
6
7. Example
declare @x int
set @x=-80;
if(@x>0)
begin
print'number is positive'
end
else if(@x<0)
begin
print'number is negative'
end
else
print'number is zero'
7
8. WHILE Loop With CONTINUE and BREAK Keywords
• Syntax:
WHILE Boolean_expression
{ sql_statement | statement_block | BREAK | CONTINUE }
{sql_statement | statement_block}
• BREAK: Causes an exit from the innermost WHILE loop.
• CONTINUE: Causes the WHILE loop to restart, ignoring any statements
after the CONTINUE keyword.
Example
DECLARE @intFlag INT
SET @intFlag = 1
WHILE (@intFlag <=5)
BEGIN
PRINT @intFlag
SET @intFlag = @intFlag + 1
END
8
9. Example : Usage of WHILE Loop with BREAK keyword
DECLARE @intFlag INT
SET @intFlag = 1
WHILE (@intFlag <=5)
BEGIN
PRINT @intFlag
SET @intFlag = @intFlag + 1
IF @intFlag = 4
BREAK;
END
GO
• Example
declare @start int
set @start=65
while(@start<=90)
begin
print char(@start)
set @start+=1
end 9
10. Example
WHILE (SELECT AVG(ListPrice) FROM Production.Product) < 300
BEGIN
UPDATE Production.Product
SET ListPrice = ListPrice * 2
SELECT MAX(ListPrice) FROM Production.Product
IF (SELECT MAX(ListPrice) FROM Production.Product) > 500
BREAK
ELSE
CONTINUE
END
• In the above example, if the average list price of a product
is less than $300, the WHILE loop doubles the prices
selects the maximum price.
• If the maximum price is less than or equal to $500,
the WHILE loop restarts and doubles the prices again.
• This loop continues doubling the prices until the
maximum price is greater than $500, and then exits
the WHILE loop. 10
11. CASE… When expressions
•Evaluates a list of conditions and returns one of multiple
possible result expressions.
•The CASE expression has two formats:
- The simple CASE expression compares an expression to
a set of simple expressions to determine the result.
- The searched CASE expression evaluates a set of
Boolean expressions to determine the result. Within a
SELECT statement, the searched CASE expression
allows for values to be replaced in the result set based on
comparison values.
Syntax for The simple CASE expression:
CASE input_expression
WHEN when_expression THEN result_expression [ ...n
]
[ELSE else_result_expression] 11
12. Example
declare @x int
set @x=20
select
case
when @x>0 then'x is positive'
when @x<0 then'x is negative'
else'x is zero'
endas'My result 1’
Example
declare @my_variable int
set @my_variable=2
select
case @my_variable
when 1 then'the number is one'
when 2 then'the number is two'
else'the number is unknown'
endas'My result 2’
Example
select first_name,
case [address]
when'bahir dar'then'your address is bahir dar'
when'Addis Abeba'then'your address is addis'
when'Gonder'then'your address is gondar'
else'address unknown'
endas'your address'
from customer
orderby first_name
12
13. Example
select first_name,last_name,
case sex
when'm'then'you are male'
when'f'then'you are female'
else'unknown'
endas'Gender'
from customer
orderby first_name
Example
select first_name,last_name,
case
when sex='m'then'you are male'
when sex='f'then'you are female'
else'unknown'
endas'Gender'
from customer
orderby first_name
13
14. Exercise
1. Using if …Else statement write a T-
SQL program to print the grade of a
student. Assume that a student table
has (StudId, FN,LN, Age, mark) and
write A if the mark is above 80, B if the
mark is between 79 and 60 and C if is
less than 60
2. Use while… loop write a T-SQL
program to find the factorial of a
number
3. Describe the Syntax of CASE……When14
15. Use the following sample database for your example
create database sales
use sales
create table customer
(
Customer_ID varchar(50)not null,
First_Name varchar(200)not null,
Last_Name varchar(200) not null,
Sex char(1),
[Address] varchar(255),
primary key(Customer_ID)
)
create table Product
(
Product_ID char(200),
Product_Name varchar(255),
purchase_Price money,
Acquired_Date date,
product_price money,
Manufacturer varchar(255),
primary key(Product_ID)
)
create table [Order]
(
Order_ID int identity(1,1),
Product_ID char(200),
Customer_ID varchar(50),
Order_Date date,
primary key(Order_ID),
foreign key(Product_ID)references
Product(Product_ID),
foreign key(Customer_ID)references
customer(Customer_ID)
)
15