Click here to Skip to main content
15,896,726 members
Home / Discussions / Database
   

Database

 
QuestionDoubt in StoredProcedure [modified] Pin
John.L.Ponratnam28-Oct-07 20:37
John.L.Ponratnam28-Oct-07 20:37 
AnswerRe: Doubt in StoredProcedure Pin
neeraj_indianic28-Oct-07 21:11
neeraj_indianic28-Oct-07 21:11 
GeneralRe: Doubt in StoredProcedure Pin
neeraj_indianic28-Oct-07 23:37
neeraj_indianic28-Oct-07 23:37 
AnswerRe: Doubt in StoredProcedure Pin
N a v a n e e t h28-Oct-07 21:16
N a v a n e e t h28-Oct-07 21:16 
AnswerRe: Doubt in StoredProcedure Pin
soni uma28-Oct-07 21:22
soni uma28-Oct-07 21:22 
AnswerRe: Doubt in StoredProcedure Pin
John-ph28-Oct-07 22:38
John-ph28-Oct-07 22:38 
GeneralRe: Doubt in StoredProcedure Pin
John.L.Ponratnam28-Oct-07 22:52
John.L.Ponratnam28-Oct-07 22:52 
GeneralRe: Doubt in StoredProcedure Pin
John-ph28-Oct-07 23:24
John-ph28-Oct-07 23:24 
ok I suggest you a better way of doing this. In sql Server we have one method of executing Dynamic Sql using sp_executesql which does a parameter substution based on the parameter definition.Let us do something like this to solve your problem...

create proc sp_temp 
@columnname varchar(25),
@value varchar(25) 
as 
 
DECLARE @SQLQuery AS NVARCHAR(500)
DECLARE @ParameterDefinition AS NVARCHAR(100)
 
set @SQLQuery = 'select * from tblname where (1=1) AND ' 
 
IF @columnname = 'EmpID'
BEGIN
set @SQLQuery = @SQLQuery + @columnname + ' =  @value' 
SET @ParameterDefinition =  '@value INT'
END
 
IF @columnname = 'EmpName' 
BEGIN
set @SQLQuery = @SQLQuery + @columnname + ' = @value' 
SET @ParameterDefinition =  '@value NVARCHAR(25)'
END
 
EXECUTE sp_executesql @SQLQuery, @ParameterDefinition, @value
 
GO



Here in the above procedure I build the ParameterDefinition list with the appropriate Datatype based on the column name. And the sp_executesql would automatically do a parameter substitution based on the DataType. Jus check it out whether it works...

 Regards
 - J O H N -



QuestionDMO objects in sql 2005 Pin
ramyasangeet28-Oct-07 20:12
ramyasangeet28-Oct-07 20:12 
AnswerRe: DMO objects in sql 2005 Pin
Mike Dimmick29-Oct-07 1:30
Mike Dimmick29-Oct-07 1:30 
Questionhow to use sp_who2 and where should i put it to check ? Pin
skyleo_200828-Oct-07 16:50
skyleo_200828-Oct-07 16:50 
AnswerRe: how to use sp_who2 and where should i put it to check ? Pin
squattyarun28-Oct-07 18:57
squattyarun28-Oct-07 18:57 
GeneralRe: how to use sp_who2 and where should i put it to check ? Pin
skyleo_200828-Oct-07 20:07
skyleo_200828-Oct-07 20:07 
QuestionUsing SqlCeEngine class in Windows application Pin
Ferudun Atakan28-Oct-07 7:59
Ferudun Atakan28-Oct-07 7:59 
AnswerRe: Using SqlCeEngine class in Windows application Pin
Scott Dorman28-Oct-07 9:26
professionalScott Dorman28-Oct-07 9:26 
AnswerRe: Using SqlCeEngine class in Windows application Pin
Mike Dimmick29-Oct-07 1:33
Mike Dimmick29-Oct-07 1:33 
QuestionSQL Server Protection Pin
mehrdadc4827-Oct-07 9:21
mehrdadc4827-Oct-07 9:21 
AnswerRe: SQL Server Protection Pin
Paul Conrad28-Oct-07 6:30
professionalPaul Conrad28-Oct-07 6:30 
GeneralRe: SQL Server Protection Pin
Hesham Amin28-Oct-07 12:41
Hesham Amin28-Oct-07 12:41 
GeneralRe: SQL Server Protection Pin
Paul Conrad29-Oct-07 17:21
professionalPaul Conrad29-Oct-07 17:21 
AnswerRe: SQL Server Protection Pin
Mike Dimmick29-Oct-07 1:35
Mike Dimmick29-Oct-07 1:35 
Questionquery for getting list of tables in a database Pin
sindhutiwari27-Oct-07 7:02
sindhutiwari27-Oct-07 7:02 
AnswerRe: query for getting list of tables in a database Pin
Hesham Amin27-Oct-07 9:15
Hesham Amin27-Oct-07 9:15 
GeneralRe: query for getting list of tables in a database Pin
Paul Conrad28-Oct-07 6:31
professionalPaul Conrad28-Oct-07 6:31 
AnswerRe: query for getting list of tables in a database Pin
Widgets28-Oct-07 0:01
Widgets28-Oct-07 0:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.