Define number of records

S

shapper

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
 
S

shapper

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top