How to Declare Variable in SQL Server Stored Procedure

In this section in SQL Server see about How to declare variable in SQL Server Stored Procedure.In this Section Use NorthWind Database in our Sql Server.

           Use declare keyword to declare the variable @ConName set particular datatype. use set as assign the value from  Database selected queries. The Unique value as assign to the variable in the Stored Procedure. Finally Display the output use Print Keyword.

Example


create procedure proc_sample1
as 
begin
declare @ConName as varchar(max)
declare @cuscount as int
set @ConName=(select ContactName from Customers where CustomerID='DRACD')
set @cuscount=(select COUNT(*) from Customers)

print @ConName
print @cuscount
end

Output
Sven Ottlieb
91




Comments

Popular posts from this blog

Insecure cookie setting: missing Secure flag

Maximum Stored Procedure Function Trigger or View Nesting Level Exceeded (limit 32) in SQL Server

Display Line Chart Using Chart.js MVC C#