1

I want to load some tables into my application but the only tables I want are the tables that have been updated.

I got in some of the databases I got an table called "Updated" but I don't have this table in every database in other databases I use the last 100 from the field ID.

What I want to do is an if/else statement where something like this happens:

IF EXISTS SELECT * FROM table1 WHERE column1 = updated 
ELSE SELECT TOP 100 table1 FROM column1 ORDER BY column1 DESC

I hope I made myself clear and hope you guys can help me.

2 Answers 2

1

you cant start else condition into second line if you not use begin and and

IF EXISTS SELECT * FROM table1 WHERE column1 = updated 
BEGIN
-- logic
END


ELSE 
BEGIN
SELECT TOP 100 table1 FROM column1 ORDER BY column1 DESC    
END

for your above quety you can write direcly

IF NOT EXISTS SELECT * FROM table1 WHERE column1 = updated 
      SELECT TOP 100 table1 FROM column1 ORDER BY column1 DESC  
Sign up to request clarification or add additional context in comments.

Comments

1

Your Sql-query is not correct. You should use somethine like this:

IF EXISTS (SELECT * FROM table1 WHERE column1 = updated)
SELECT * FROM table1 WHERE column1 = updated 
ELSE SELECT TOP 100 table1 FROM column1 ORDER BY column1 DESC

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.