Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Row Number on Insert

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2008-02-27 : 14:01:39
Hello,

I am inserting a few records for test in a table:

insert into dbo.Articles(ArticleID, BlogID, AuthorID, Body)
select
newid(),
BlogID,
UserID,
'Body ' + cast(n as nvarchar)
from (select n, newid() as ArticleID, BlogID, UserID
from @Numbers
cross join dbo.Blogs
cross join dbo.Users) as DummyData
where n <= @articles

In my Body column I get Body 1, Body 2, Body 1, ...

What am I doing wrong?

What should I do to get Body 1, Body 2, Body 3, Body 4, ...

Thanks,
Miguel

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2008-02-27 : 14:36:49
Done ... I was missing one thing.

Thanks,
Miguel
Go to Top of Page

dineshasanka
Yak Posting Veteran

72 Posts

Posted - 2008-02-27 : 17:48:37
Better if you update with ur fixed query

---------------------
http://dineshasanka.spaces.live.com/
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2008-02-27 : 18:46:50
Hi,

My code restarts the article numbering for each blog.
The code is fine ... I was just expecting something different ...
This was just a copy/paste mistake and I didn't notest.

Thanks,
Miguel
Go to Top of Page
   

- Advertisement -