NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

--Stored Procedure[insert,update,delete]
create or alter procedure insert_demo(
@stud_name Varchar(50),
)
AS
BEGIN
IF EXISTS (SELECT 1 FROM student WHERE stud_id=@stud_id)
BEGIN
UPDATE student set stud_name=@stud_name WHERE stud_id=@stud_id
END
ELSE
BEGIN
INSERT into student Values (@stud_name)
END
END

--multi record insert[Table Variable]
CREATE or alter PROCEDURE demo_test
@temp [dbo].[test_table_var] Readonly
AS
BEGIN
IF exists(select 1 from @temp as tp left join [dbo].[employee] as emp on emp.e_id=tp.e_id where emp.e_id is null)
Begin
insert into [dbo].[employee] select tp.e_id,tp.e_name,tp.e_salary from @temp as tp left join [dbo].[employee]
as emp on emp.e_id=tp.e_id where emp.e_id is null
end
IF exists(select 1 from @temp as tp left join [dbo].[employee] as emp on emp.e_id=tp.e_id where emp.e_id is not null)
Begin
update emp set emp.e_id=tp.e_id,emp.e_name=tp.e_name,emp.e_salary=tp.e_salary from @temp as tp left join [dbo].[employee]
as emp on emp.e_id=tp.e_id where emp.e_id is not null
end
END
GO

CREATE TYPE [test_table_var] AS TABLE
(
e_id int not null,
e_name nvarchar(max)
)
GO

declare @var [dbo].[test_table_var]
insert into @var values(1,'demo')
select *from @var

--Scalar Function[using merge]
CREATE OR ALTER FUNCTION [dbo].[salary_increment]
(
@Increment int,
@Salary numeric(18,2)
)
RETURNS numeric(18,2)
AS
BEGIN
RETURN @salary+(@salary*@Increment/100);
END

declare @employee_detail [dbo].[emp_detail] --tablevariable
insert into @employee_detail values(9,'ri',20000,1);
insert into @employee_detail values(10,'test',45000,1);
select * from @employee_detail;

MERGE into [dbo].[tbl_employee] as desa
USING(
select * from @employee_detail
) as sou
on sou.ID=desa.ID
WHEN MATCHED THEN
update set desa.EMP_NAME=sou.EMP_NAME,
desa.SALARY= [dbo].[salary_increment](20,sou.SALARY)
WHEN NOT MATCHED THEN
insert(EMP_NAME,SALARY,DEPARTMENT_ID) values (sou.EMP_NAME,[dbo].[salary_increment](20,sou.SALARY),sou.DEPARTMENT_ID);

--Trigger
create or alter TRIGGER my_triggu
ON student
AFTER INSERT,DELETE,UPDATE
AS
BEGIN
IF Exists(select 0 from inserted)
begin
If exists(select 0 from deleted)
begin
INSERT INTO [dbo].[tbl_logs]([remarks],[date_of_op],[stud_name])
select 'updated',getdate(),[stud_name] from inserted;
end else
begin
INSERT INTO [dbo].[tbl_logs]([remarks],[date_of_op],[stud_name])
select 'inserted',getdate(),[stud_name] from inserted;
end
end else
begin
INSERT INTO [dbo].[tbl_logs]([remarks],[date_of_op],[stud_name])
select 'deleted',getdate(),[stud_name] from deleted;
end
END
GO

--query
--1
select [day_of_operation] from [dbo].[flightmast] where [day_of_operation] like
concat('%',(select Datename(dw,@travel_date)),'%') and flight_id=@flight_id
--2
select [Routing],count([flight_id]) from [dbo].[flightmast] group by [Routing];
select * from (select [flight_id],[Routing] from [dbo].[flightmast]) as f
pivot(
count([flight_id]) for routing in ([Via ATQ],[Via PAT],[Via AMD])
)as pivot_db
--3
--where f.[effective_from] between DATEADD(m,-6,GETDATE()) and GETDATE() order by f.[flight_id];
--4
SELECT stud_name,
max(case when s_id = 1 and stud_marks<50 then stud_marks end) 'dbms' ,
from student group by stud_name;
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.