Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2002
    Location
    India
    Posts
    37

    Unanswered: Help me in this Query

    hello all,
    I have a table with the Following structure. .. . .

    Catid CategoryName Desc
    _________________________________________
    1 A Hello all Welcome
    2 A Thanks For all
    3 B Did u come yesterday ?
    4 B Shall we got out.. ?

    now i need a procedure which will accept a Categoryname as Arguement and will return the "desc " First time First record, second time second record,and so on depending on the N number of entries in each and evry category..
    Please help me how do i go about..
    I guess some how i am not getting any ideas..
    Help me..

    sai

  2. #2
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    809
    IS this what you are looking for?

    Code:
    create table #Category(CatID int,CategoryName varchar(10),[Desc] varchar(30))
    go
    insert into #Category values(1, 'A', 'Hello all Welcome')
    insert into #Category values(2, 'A', 'Thanks For all')
    insert into #Category values(3, 'B', 'Did u come yesterday ?') 
    insert into #Category values(4, 'B', 'Shall we got out.. ?')
    go
    select * from #Category
    go
    create procedure #GetCat(
    @CategoryName   varchar(10),
    @Desc           varchar(30) = Null)
    as
    select min([Desc])
      from #Category 
     where CategoryName = @CategoryName 
       and ([Desc] > @Desc or @Desc is null)
    return 0
    go
    exec #GetCat 'A'
    exec #GetCat 'A','Hello all Welcome'
    exec #GetCat 'A','Thanks For all'
    exec #GetCat 'B'
    exec #GetCat 'B','Did u come yesterday ?'
    exec #GetCat 'B','Shall we got out.. ?'
    go
    Paul Young
    (Knowledge is power! Get some!)

  3. #3
    Join Date
    Aug 2002
    Location
    India
    Posts
    37

    Thx for the Reply , But it dint worked..

    hi Paul,
    Thanks for the reply.

    yeah i am looking for something similar but not the same..

    I need like below..

    exec #getdat 'A'
    should give me 'Hello all WElcome'
    and again if i execute the same (i.e.) exec #getdat 'A'
    then it should give me 'Thanks .. '
    and again if i execute 'hello all welcome '
    like this...
    i am looking for something like Rand function do we have any ?


    Thanks
    sai

  4. #4
    Join Date
    Feb 2002
    Location
    Houston, TX
    Posts
    809
    what's a RAND function?
    Paul Young
    (Knowledge is power! Get some!)

  5. #5
    Join Date
    Dec 2002
    Location
    Czech Republic
    Posts
    249
    What about

    select top 1 *
    from #Category
    where CategoryName=@CategoryName
    order by NEWID()

    You also can order by CHECKSUM(NEWID()) for more random distribution of results.

  6. #6
    Join Date
    Aug 2002
    Location
    India
    Posts
    37

    Thanks a lot...

    Thanks a lot Ispaleny... It solved my purpose...

    thanks and regards
    SAI

Posting Permissions

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