Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using If Statement to check field before database update

Status
Not open for further replies.

topcat01

Programmer
Jul 10, 2003
83
GB
Hi,

I have a SQL script for MS SQLServer that creates a series of tables, one table is named 'META' and contains the field 'dbver' (database version). I would like to update my script so that updates to the database can be applied by checking the database version and would like to know if this is possible? I cannot figure out how to compare a value in the database using the script (peusdo-code below). Any help would be very useful, hope this makes sense! Thank you

if dbver = 1 then // how do i read the current value in the database?
begin
perform updates on database for new version
insert into meta values('2'); go
end

if dbver = 2 then
begin
perform updates on database for new version
insert into meta values('3'); go
end


 
Something like this:

Code:
if Not Exist(Select * From META Where dbver = '2')// how do i read the current value in the database?
begin
perform updates on database for new version
insert into meta values('2');
end

if Not Exist(Select * From META Where dbver = '3')
begin
perform updates on database for new version
insert into meta values('3');
end



-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thank you George, I will give your suggestion a try!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top