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.
| Author |
Topic |
|
abenitez77
Yak Posting Veteran
53 Posts |
Posted - 2011-10-21 : 09:28:18
|
| I have a db that I want to insert test data into. I want to enter in specific info. table name: demo_ImageTableColumns: RecKey(int), ImageSeq(int), ImagePath(varchar), ImageName(varchar)I want to insert data to this table. I want Reckey to be incremental by "1", starting with "51"ImageSeq is a set value - "2"ImagePath is a set value (\\usatl02eras40\Audit Strategy\ASTRATEGY\Projects\Middleware\Demo\Claims\)ImageName is "SupportDoc.pdf" with a number at the end of the name, incrementing with every record (ie, "SupportDoc1.pdf", "SupportDoc2.pdf", etc..) starting with number "1". |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-21 : 09:33:00
|
make reckey as identity type with seed as 1 and increment as 1 ie IDENTITY(1,1)and make insert likeINSERT INTO demo_ImageTable (ImageSeq, ImagePath, ImageName)SELECT 2,'\\usatl02eras40\Audit Strategy\ASTRATEGY\Projects\Middleware\Demo\Claims\','SupportDoc'+ CAST(number AS varchar(2)) + '.pdf'FROM master..spt_valuesWHERE type='p'AND number BETWEEN 1 AND 51 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
abenitez77
Yak Posting Veteran
53 Posts |
Posted - 2011-10-21 : 09:54:32
|
| reckey can't be an identity column. It already has data in it and it can have duplicate values. Also, I said below incremental by "1" , starting with "51". I was wrong, it should be incremental by "1", starting with "1". Think of it as a value that is a primary key of another table. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-21 : 10:00:46
|
quote: Originally posted by abenitez77 reckey can't be an identity column. It already has data in it and it can have duplicate values. Also, I said below incremental by "1" , starting with "51". I was wrong, it should be incremental by "1", starting with "1". Think of it as a value that is a primary key of another table.
then put it as number itselfINSERT INTO demo_ImageTable (RecKey,ImageSeq, ImagePath, ImageName)SELECT number,2,'\\usatl02eras40\Audit Strategy\ASTRATEGY\Projects\Middleware\Demo\Claims\','SupportDoc'+ CAST(number AS varchar(2)) + '.pdf'FROM master..spt_valuesWHERE type='p'AND number BETWEEN 1 AND 51 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
abenitez77
Yak Posting Veteran
53 Posts |
Posted - 2011-10-21 : 10:21:33
|
| thanks! worked great. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-21 : 10:29:00
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|