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
 General SQL Server Forums
 New to SQL Server Programming
 automated creation of promo codes

Author  Topic 

kabucek
Starting Member

7 Posts

Posted - 2009-04-23 : 12:23:30
hello,

I have this query for creating one code at a time

INSERT INTO `database1`.`table1` (
`couponCode`,
`pageCount`
)
VALUES (
'promo-001002', '2'
);

but this will create only one code.
I need a query that will create 200 codes with starting number "-001002".
Is there a way to do it?

Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-23 : 12:30:35
Are you using MySQL?

INSERT Table1
SELECT 'promo-' + REPLACE(STR(1002 + Number, 6, 0), ' ', '0')
FROM master..spt_values
WHERE type = 'P' and number <= 199



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

kabucek
Starting Member

7 Posts

Posted - 2009-04-23 : 12:37:50
OK,
but what if I have to provide another values, like:

`allowedUseCount` ,
`cancelledFlag` ,
`couponCode` ,
`creationTime` ,
`expirationTime` ,
`itemID` ,
`pageCount` ,
`regPromoCodeString` ,
`sourceItemID` ,
`sourceProcessName` ,
`storePromoCodeString` ,
`usedCount` ,
`useHistory` ,
`userID`

How can your query be implemented?

Thanks
Go to Top of Page

kabucek
Starting Member

7 Posts

Posted - 2009-04-23 : 12:42:55
but they all can be null
Go to Top of Page
   

- Advertisement -