Click here to Skip to main content
15,888,239 members
Home / Discussions / Database
   

Database

 
SuggestionRe: Employee Year Calculation Pin
Kornfeld Eliyahu Peter9-Sep-14 10:38
professionalKornfeld Eliyahu Peter9-Sep-14 10:38 
QuestionRe: Employee Year Calculation Pin
Eddy Vluggen10-Sep-14 10:07
professionalEddy Vluggen10-Sep-14 10:07 
AnswerRe: Employee Year Calculation Pin
Kornfeld Eliyahu Peter10-Sep-14 10:20
professionalKornfeld Eliyahu Peter10-Sep-14 10:20 
QuestionMySQL CREATE EVENT Question Pin
Jassim Rahma8-Sep-14 23:08
Jassim Rahma8-Sep-14 23:08 
AnswerRe: MySQL CREATE EVENT Question Pin
Eddy Vluggen9-Sep-14 8:51
professionalEddy Vluggen9-Sep-14 8:51 
QuestionArabic langauge not display when i make search by arabic langauge why Pin
ahmed_sa5-Sep-14 20:44
ahmed_sa5-Sep-14 20:44 
AnswerRe: Arabic langauge not display when i make search by arabic langauge why Pin
Bernhard Hiller7-Sep-14 22:25
Bernhard Hiller7-Sep-14 22:25 
AnswerRe: Arabic langauge not display when i make search by arabic langauge why Pin
Richard Deeming8-Sep-14 2:02
mveRichard Deeming8-Sep-14 2:02 
I'm repeating myself here:
Don't use string concatenation to build a dynamic SQL query. Your code will be susceptible to SQL Injection[^].

If you really need to use a dynamic query, use sp_executesql[^] to execute it:
SQL
CREATE Procedure sp_EmployeeSelect
    @EmployeeName nvarchar(50)
AS
Declare @SQLQuery as nvarchar(2000)

SET @SQLQuery = N'SELECT * from Employee Where (1=1)'
If @EmployeeName <> ''
    Set @SQLQuery = @SQLQuery + N' AND (EmployeeName LIKE N''%'' + @EmployeeName + N''%'')'

Exec sp_executesql @SQLQuery,
    N'@EmployeeName nvarchar(50)',
    @EmployeeName


However, in this case, as with all of your QA questions, you don't need a dynamic query:
SQL
CREATE Procedure sp_EmployeeSelect
    @EmployeeName nvarchar(50)
AS
    SELECT
        *
    FROM
        Employee
    WHERE
        @EmployeeName = N''
    Or
        EmployeeName Like N'%' + @EmployeeName + N'%'




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


QuestionSelect records between day, time 05:00:00 and day+1 until time 05:00:00 Pin
Ambertje4-Sep-14 0:07
Ambertje4-Sep-14 0:07 
AnswerRe: Select records between day, time 05:00:00 and day+1 until time 05:00:00 Pin
Chris Quinn4-Sep-14 0:13
Chris Quinn4-Sep-14 0:13 
GeneralRe: Select records between day, time 05:00:00 and day+1 until time 05:00:00 Pin
Ambertje4-Sep-14 1:40
Ambertje4-Sep-14 1:40 
AnswerRe: Select records between day, time 05:00:00 and day+1 until time 05:00:00 Pin
Eddy Vluggen4-Sep-14 0:31
professionalEddy Vluggen4-Sep-14 0:31 
GeneralRe: Select records between day, time 05:00:00 and day+1 until time 05:00:00 Pin
Ambertje4-Sep-14 1:41
Ambertje4-Sep-14 1:41 
QuestionRe: Select records between day, time 05:00:00 and day+1 until time 05:00:00 Pin
Richard MacCutchan4-Sep-14 6:19
mveRichard MacCutchan4-Sep-14 6:19 
GeneralRe: Select records between day, time 05:00:00 and day+1 until time 05:00:00 Pin
Eddy Vluggen4-Sep-14 8:26
professionalEddy Vluggen4-Sep-14 8:26 
GeneralRe: Select records between day, time 05:00:00 and day+1 until time 05:00:00 Pin
Jörgen Andersson4-Sep-14 10:57
professionalJörgen Andersson4-Sep-14 10:57 
GeneralRe: Select records between day, time 05:00:00 and day+1 until time 05:00:00 Pin
Eddy Vluggen4-Sep-14 11:54
professionalEddy Vluggen4-Sep-14 11:54 
GeneralRe: Select records between day, time 05:00:00 and day+1 until time 05:00:00 Pin
Jörgen Andersson4-Sep-14 18:39
professionalJörgen Andersson4-Sep-14 18:39 
GeneralRe: Select records between day, time 05:00:00 and day+1 until time 05:00:00 Pin
Corporal Agarn5-Sep-14 0:51
professionalCorporal Agarn5-Sep-14 0:51 
GeneralRe: Select records between day, time 05:00:00 and day+1 until time 05:00:00 Pin
Richard Deeming5-Sep-14 1:50
mveRichard Deeming5-Sep-14 1:50 
AnswerRe: Select records between day, time 05:00:00 and day+1 until time 05:00:00 Pin
Corporal Agarn4-Sep-14 0:55
professionalCorporal Agarn4-Sep-14 0:55 
AnswerRe: Select records between day, time 05:00:00 and day+1 until time 05:00:00 Pin
Richard Deeming4-Sep-14 1:41
mveRichard Deeming4-Sep-14 1:41 
GeneralRe: Select records between day, time 05:00:00 and day+1 until time 05:00:00 Pin
Ambertje4-Sep-14 1:46
Ambertje4-Sep-14 1:46 
GeneralRe: Select records between day, time 05:00:00 and day+1 until time 05:00:00 Pin
Corporal Agarn4-Sep-14 3:06
professionalCorporal Agarn4-Sep-14 3:06 
GeneralRe: Select records between day, time 05:00:00 and day+1 until time 05:00:00 Pin
sai sruthi8-Sep-14 23:38
sai sruthi8-Sep-14 23:38 

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.