I am generating SQL commends using Sybase to insert some new rows into a table based on the previous contents (working with an old ORM) and was wondering if there is a way to execute generated SQL without copy and paste?
I’m using something like
SELECT 'INSERT INTO Mapper VALUES (''' + ClassName + ''', ''NewObject'', ''NewId'', '''+convert(varchar(10), max(Sequence)+1)+''')'
FROM Mapper WHERE ClassName IN ('James', 'Steve') GROUP BY ClassName
For a table like
ClassName | ObjectName | ID | Sequence
This outputs results like:
INSERT INTO Mapper VALUES ('James', 'NewObject', 'NewId', '38')
INSERT INTO Mapper VALUES ('Steve', 'NewObject', 'NewId', '24')
Is it possible to now run this genereated SQL without having to copy and paste within Sybase with just SQL (using Aqua Data Studio)?
Currently I just copy and paste it back into the same window
Thanks,
—
Note if this makes any difference it’ll be for 2000+ rows
P.s. I’ve just noticed I used the word like a lot, sorry ^_^
You could use a
CURSORon your statement, and theEXECcommand to execute the SQL generated in each row.I’m assuming this is a one off task, rather than an ongoing process, and there’s a reason why you don’t use
INSERT table SELECT....