December 2, 2009 at 1:33 am
Hi,
Here is my table.
table t1
--
seq int PK
num int unique
name char
On num 100, 200, 300, 400, 500 .. etc I have a header. Starting with every hundred.
I want to insert a new blank row before every header in my table with the num 99, 199, 299, 399, 499 ..
For now I do this manually:
INSERT INTO t1 (num) VALUES (99);
INSERT INTO t1 (num) VALUES (199);
INSERT INTO t1 (num) VALUES (299);
INSERT INTO t1 (num) VALUES (399);
INSERT INTO t1 (num) VALUES (499);
Must be some more efficient way to do this.
Something like ?
Insert a new row for every row in table and set the num value minus (-) 1
//
Regards
December 2, 2009 at 5:06 am
if your table t1 already has those values, you should be able to use the integer modulus to determine/select only those values that are perfectly divisible by 100; then do exactly as you said, insert that number minus one.
INSERT INTO t1
SELECT num -1
from T1 WHERE (num %100) = 0
note
Lowell
December 3, 2009 at 1:01 am
Thx Lowell!
It worked! I first had some issue regarding the modulus operator "%". Beacuse I use ASA (sybase) in this application and in ASA, the percent sign is a comment marker. So I first had to turn this option off then it worked.
Working code below:
SET OPTION PERCENT_AS_COMMENT=OFF
INSERT INTO t1 (num)
SELECT num -1
from myDatabase.t1
WHERE (num %100) = 0
//
Regards
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply