Good day everyone.
Here is my situation. I have a user that deleted data from my production database and they would like to have the data back in the database. In order to do that I have to retrieve the data from a database backup but the database backup is on a different server and it is not connected to the same domain. What I have to do is to extract the data from the table and insert it back in the production database using the insert command. I have then created a select command that return the information as an insert command.
Here is an example.
I have a table CALLED TABLE1 with col1, col2, col3.
My co11,col2 are int and col3 is varchar(10)
I created my select statement like this.
SELECT 'INSERT INTO TABLE1 (COL1, COL2, COL3)
VALUES (' + CAST (COL1 AS VARCHAR (6)) +', ' + CAST (COL2 AS VARCHAR (6)) +', ''' + COL3 +'''' + ');'
FROM TABLE1
WHERE COL1 = 15434
My query return as follow.
INSERT INTO TABLE1 )COL1, COL2, COL3) VALUES (15434, 1, 'TEST')
From that point on I can use the query to insert back in my production database. Where I have an issue is if one of the column is null then the query return null. I would like to know if anyone would have a solution to turn the null column to something else so the result does not return null value.
Thanks in advance and let me know if you require more detail.
Here is my situation. I have a user that deleted data from my production database and they would like to have the data back in the database. In order to do that I have to retrieve the data from a database backup but the database backup is on a different server and it is not connected to the same domain. What I have to do is to extract the data from the table and insert it back in the production database using the insert command. I have then created a select command that return the information as an insert command.
Here is an example.
I have a table CALLED TABLE1 with col1, col2, col3.
My co11,col2 are int and col3 is varchar(10)
I created my select statement like this.
SELECT 'INSERT INTO TABLE1 (COL1, COL2, COL3)
VALUES (' + CAST (COL1 AS VARCHAR (6)) +', ' + CAST (COL2 AS VARCHAR (6)) +', ''' + COL3 +'''' + ');'
FROM TABLE1
WHERE COL1 = 15434
My query return as follow.
INSERT INTO TABLE1 )COL1, COL2, COL3) VALUES (15434, 1, 'TEST')
From that point on I can use the query to insert back in my production database. Where I have an issue is if one of the column is null then the query return null. I would like to know if anyone would have a solution to turn the null column to something else so the result does not return null value.
Thanks in advance and let me know if you require more detail.