• super48 (4/9/2014)


    then try this one if u want to use *--

    create procedure startrred

    @hourstarted varchar(10)

    as

    begin

    if(@hourstarted!='*')

    begin

    Select *

    from Production where hourworked>@hourstarted

    END

    else

    begin

    select * from Production where hourworked>15

    end

    end

    I would NEVER recommend passing in a character that will be implicitly converted to an int like this. One of the issues with this type of thing is what happens when you pass a character string that cannot be converted to an int?

    However, if you go with this path keep it simple. There is no need to have separate select statements. This procedure can be greatly simplified to:

    create procedure startrred

    (

    @hourstarted varchar(10)

    )as

    if @hourstarted = '*' set @hourstarted = '15'

    Select *

    from Production where hourworked>@hourstarted

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/