Create paramater and pass it into SQL query

  • Currently, I have a problem with creating parameters. For the following data set, I can create a parameter with FiscalYear, which I can set the 2010 and 2011 as the values. It is working fine. But I need to create a parameter with

    Name to just show ITA or OJT or SUS or all of them How can I do that?

    pool name fiscalYear

    1212 eoc-OJT-Adult 2010

    1213 eoc-ITA-Adult 2010

    1214 eoc-SUS-Adult 2010

    1300 eoc-OJT-Adult 2011

    1311 eoc-ITA-Adult 2011

    1322 eoc-SUS-Adult 2011

    ....

    Thanks

  • SUBSTRING(FiscalYear, 5, 3)

  • Thanks.

    by the way, how can I create a parameter by using something like '%xxx%'?

  • is the data always the same? or will it always follow this format ###-###-##### ##### ie eoc-ABC-Adult 2011

    If not then perhaps something like this would be better to start your substring at the - rather than specifiying a start point

    declare @string varchar (50)

    set @string='1322 eoc-SUS-Adult 2011'

    select @string, substring(@string,charindex('-',@string)+1,3)

    Next one could ask will the returning data always be 3 characters long? or could it be different each time? SUS, ABC, ADDED, FFFFFFFFFF?

    we can get round that like this

    declare @string varchar (50)

    set @string='1322 eoc-SUS-Adult 2011'

    select @string, substring(substring(@string,charindex('-',@string)+1,99),0,charindex('-',substring(@string,charindex('-',@string)+1,99)))

    ***The first step is always the hardest *******

  • in answer to your other question

    set @param='%'+XXXX+'%'

    ***The first step is always the hardest *******

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply