PC Review


Reply
Thread Tools Rate Thread

Define number of records

 
 
shapper
Guest
Posts: n/a
 
      27th Feb 2008
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
 
Reply With Quote
 
 
 
 
shapper
Guest
Posts: n/a
 
      27th Feb 2008
On Feb 27, 12:52 am, shapper <mdmo...@gmail.com> 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
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
number of records in form do not match number of records in querie Graciela Microsoft Access Database Table Design 13 5th Jun 2009 11:37 PM
formula to define the number of gallons used CindyAnn Microsoft Excel Programming 4 9th Sep 2008 02:47 PM
Use a formula to define row number =?Utf-8?B?SU5lZWRJRA==?= Microsoft Excel Misc 2 13th Jun 2007 12:33 AM
How do I define the same name to a number of different worksheets. =?Utf-8?B?TWFsY29sbQ==?= Microsoft Excel Programming 1 23rd Sep 2004 05:59 PM
Number of Records pulled by Query don't match number of records in table Rebekah Microsoft Access Queries 7 15th Sep 2004 08:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:59 PM.