Define number of records

Discussion in 'ASP .Net' started by shapper, Feb 27, 2008.

  1. shapper

    shapper Guest

    Hello,

    I am using a Numbers table to create test data:

    -- Categories
    insert into dbo.Categories (CategoryID, [Name])
    select
    newid(),
    'Category ' + cast(n as nvarchar)
    from @Numbers
    where n <= @categories

    @categories is the number of categories I want to create. I create
    articles the same way.

    Now I want to associate each article to X categories.

    However, for each article X should be a random number between @Min and
    @Max.

    Of course I will set @Max smaller than the number or articles.

    I also have a Random Function that returns an integer between
    @StartInt and @EndInt:

    create function dbo.NumberTable
    (
    @startint int,
    @endint int
    )
    ....

    My question is how to do the inserting?
    What I have in this moment is the following:

    insert into dbo.ArticlesCategories(ArticleID, CategoryID)
    select ArticleID, CategoryID
    from dbo.Articles
    join dbo.Categories on CategoryID in (
    ?????????????????????????????????????
    from dbo.Categories c
    order by newid()
    )

    Thanks,
    Miguel
     
    shapper, Feb 27, 2008
    #1
    1. Advertising

  2. shapper

    shapper Guest

    On Feb 27, 12:52 am, shapper <> wrote:
    > Hello,
    >
    > I am using a Numbers table to create test data:
    >
    > -- Categories
    > insert into dbo.Categories (CategoryID, [Name])
    > select
    > newid(),
    > 'Category ' + cast(n as nvarchar)
    > from @Numbers
    > where n <= @categories
    >
    > @categories is the number of categories I want to create. I create
    > articles the same way.
    >
    > Now I want to associate each article to X categories.
    >
    > However, for each article X should be a random number between @Min and
    > @Max.
    >
    > Of course I will set @Max smaller than the number or articles.
    >
    > I also have a Random Function that returns an integer between
    > @StartInt and @EndInt:
    >
    > create function dbo.NumberTable
    > (
    > @startint int,
    > @endint int
    > )
    > ...
    >
    > My question is how to do the inserting?
    > What I have in this moment is the following:
    >
    > insert into dbo.ArticlesCategories(ArticleID, CategoryID)
    > select ArticleID, CategoryID
    > from dbo.Articles
    > join dbo.Categories on CategoryID in (
    > ?????????????????????????????????????
    > from dbo.Categories c
    > order by newid()
    > )
    >
    > Thanks,
    > Miguel


    Sorry, wrong forum.

    Thanks,
    Miguel
     
    shapper, Feb 27, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luke Airig
    Replies:
    0
    Views:
    821
    Luke Airig
    Dec 31, 2003
  2. theotyflos
    Replies:
    3
    Views:
    506
    Thomas Matthews
    Feb 19, 2004
  3. mamu
    Replies:
    3
    Views:
    1,419
  4. Dan

    Delete records or update records

    Dan, May 10, 2004, in forum: ASP General
    Replies:
    1
    Views:
    486
    Ray at
    May 10, 2004
  5. Replies:
    3
    Views:
    706
    Anthony Jones
    Nov 2, 2006
Loading...

Share This Page