March 11, 2013 at 6:40 pm
I HAVE A TABLE WITH THREE FIELD COMCOD nchar(4) DUPLICATE ALLOWED FOREIGN KEY, ACTCODE nvarchar(6) PRIMARY KEY, ACTDESC nvarchar(250).
TABLE IS LIKE
COMCOD ACTCODE ACTDESC
3306 180001 ADVANCE TO STAFF
3306 180002 ADVANCE TO OTHERS
3306 180003 ADVANCE TO SITE OFFICE
NOW I WOULD LIKE TO INSERT 10 ROWS IN A SINGLE COMMAND STARTS FROM 180010 TO 180100 WITH SEQUENCE 0F ACTCODE=ACTCODE+10 AND ACTDESC WITH NULL VALUES AND COMCOD WILL BE THE SAME FOR EVERY ROW.
March 11, 2013 at 8:09 pm
Rauf Miah
Your request sounds very much like home work. I am not adverse to helping a student, but first post what you have attempted, and the error message returned if any, or the partial results, but not meeting your criteria.
March 12, 2013 at 4:28 am
Rauf Miah (3/11/2013)
I HAVE A TABLE WITH THREE FIELD COMCOD nchar(4) DUPLICATE ALLOWED FOREIGN KEY, ACTCODE nvarchar(6) PRIMARY KEY, ACTDESC nvarchar(250).TABLE IS LIKE
COMCOD ACTCODE ACTDESC
3306 180001 ADVANCE TO STAFF
3306 180002 ADVANCE TO OTHERS
3306 180003 ADVANCE TO SITE OFFICE
NOW I WOULD LIKE TO INSERT 10 ROWS IN A SINGLE COMMAND STARTS FROM 180010 TO 180100 WITH SEQUENCE 0F ACTCODE=ACTCODE+10 AND ACTDESC WITH NULL VALUES AND COMCOD WILL BE THE SAME FOR EVERY ROW.
What you could do with here is a numbers/tally table.
Check out: -
Uses of Tally Table Part 1[/url],
Uses of Tally Table Part 2[/url],
The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url]
Hidden RBAR: Counting with Recursive CTE's[/url]
As bitbucket, I'm reluctant to provide you with a ready made solution. But if you want to gives it a shot based on the articles above then post what you've done then I'm more than happy to help.
March 12, 2013 at 4:51 am
you can use some sys tables (or any other available table) as kind of tally one:
INSERT YourTable (COMCOD, ACTCODE, ACTDESC)
SELECT TOP 10
3306 AS COMCOD
,180000 +
(ROW_NUMBER() OVER (ORDER BY (SELECT NULL))) * 10 AS ACTCODE
,NULL AS ACTDESC
FROM sys.columns
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply