Results 1 to 6 of 6

Thread: need help at sort become a parameter

  1. #1
    Join Date
    Jul 2003
    Posts
    421

    need help at sort become a parameter

    Hi all,
    I have store procedure
    create proc select_test
    (@SubType varchar(50),
    @sort varchar(4)
    )
    AS
    ..................
    order by SampleYear @sort and I got error at @sort
    any hit??
    Thank you!
    ________
    Starcraft Replays
    Last edited by sql; 03-06-2011 at 01:51 AM.

  2. #2
    Join Date
    Aug 2003
    Location
    London
    Posts
    110
    You need to use functions, rather than sp , if you want to use them in the select statment.

  3. #3
    Join Date
    Jul 2003
    Posts
    421
    hi
    any detail? the reason I write a store procedure is i want to call from java bean. can I call a function from java ??
    thank you
    ________
    Vaporite Solo
    Last edited by sql; 03-06-2011 at 01:51 AM.

  4. #4
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    If sql server,

    create proc select_test
    (@SubType varchar(50),
    @sort varchar(4)
    )
    AS
    select * from sysobjects order by
    case @sort when '1' then info
    else id end

  5. #5
    Join Date
    Jul 2003
    Posts
    421
    Hi mak,
    I did use MS Sql, I try the suggestion and still got error

    rop proc select_Type
    go
    create proc select_Type
    (@SubType varchar(50),
    @sort varchar(4)
    )
    AS

    begin
    begin transaction
    select FieldNumber, Name, HiTiter, SubType, Storage,SampleRegion, SampleYear
    from ViruName00
    where SubType like'%' +@SubType+ '%'

    union
    select FieldNumber, Name, HiTiter, SubType, Storage,SampleRegion, SampleYear
    from ViruName01
    where SubType like'%' +@SubType+ '%'

    union
    select FieldNumber, Name, HiTiter, SubType, Storage,SampleRegion, SampleYear
    from ViruName02
    where SubType like'%' +@SubType+'%'

    union
    select FieldNumber, Name, HiTiter, SubType, Storage,SampleRegion, SampleYear
    from ViruName03
    where SubType like'%' +@SubType+'%'

    union
    select FieldNumber, Name, HiTiter, SubType, Storage,SampleRegion, SampleYear
    from ViruName04
    where SubType like'%' +@SubType+ '%' order by case @sort
    when '1' then
    SampleYear asc
    else SampleYear desc

    if @@error <>0 or @@rowcount !=1
    begin
    rollback
    return
    end
    commit transaction
    end
    ________
    Suzuki rm65
    Last edited by sql; 03-06-2011 at 01:51 AM.

  6. #6
    Join Date
    Jul 2003
    Posts
    421
    Hi ,
    any suggestions?
    ________
    C200
    Last edited by sql; 03-06-2011 at 01:52 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •