Welcome to the Windows community forum and interact with 3 million technical staff. -- add the Stored Procedure ifexists (select * distinct) dropprocusp_insertgocreateprocusp_insert (@ tablenvarchar (255), @ valuesnvarchar (max
Welcome to the Windows community forum and interact with 3 million technical staff> go to -- General to add the stored procedure if exists (select * from sysobjects where name = 'usp _ insert ') drop proc usp_insert go create proc usp_insert (@ table nvarchar (255), @ values nvarchar (max
Welcome to the Windows community forum and interact with 3 million technicians>
-- General addition of Stored Procedures
If exists (select * from sysobjects where name = 'usp _ insert ')
Drop proc usp_insert
Go
Create proc usp_insert
(
@ Table nvarchar (255 ),
@ Values nvarchar (max)
)
As
Declare @ SQL nvarchar (max)
Set @ SQL = 'insert into ['+ @ table +'] values ('+ @ values + ')'
Exec sp_executesql @ SQL
Go
Exec usp_insert 'customer', '''tom '', ''100 '''
Go
-- General delete stored procedure
If exists (select * from sysobjects where name = 'usp _ delete ')
Drop proc usp_delete
Go
Create proc usp_delete
(
@ Table nvarchar (255 ),
@ Where nvarchar (max)
)
As
Declare @ SQL nvarchar (max)
Set @ SQL = 'delete from ['+ @ table +']'
If (@ where is not null and len (@ where)> 0)
Set @ SQL + = 'where' + @ where
Exec sp_executesql @ SQL
Go
Exec usp_delete 'customer', 'Id = 1'
Go
-- General Stored Procedure Modification
If exists (select * from sysobjects where name = 'usp _ Update ')
Drop proc usp_update
Go
Create proc usp_update
(
@ Table nvarchar (255 ),
@ Set nvarchar (max ),
@ Where nvarchar (max)
)
As
Declare @ SQL nvarchar (max)
Set @ SQL = 'Update ['+ @ table +'] set' + @ set
If (@ where is not null and len (@ where)> 0)
Set @ SQL + = 'where' + @ where
Exec sp_executesql @ SQL
Go
Exec usp_update 'customer', 'name = ''smile ''', 'Id = 1'
Go
-- General query stored procedures
If exists (select * from sysobjects where name = 'usp _ select ')
Drop proc usp_select
Go
Create proc usp_select
(
@ Table nvarchar (255 ),
@ Where nvarchar (max)
)
As
Declare @ SQL nvarchar (max)
Set @ SQL = 'select * from ['+ @ table +']'
If (@ where is not null and len (@ where)> 0)
Set @ SQL + = 'where' + @ where
Exec sp_executesql @ SQL
Go
Exec usp_select 'customer', 'Id = 2'
Go