0

How to insert if/else in the query?

This is my sqlcommand query :

 sqlcommand ("select Machine_Code,Machine_Name,Status from
 Machine_Master where '" & combolinecode.Text & "' = Line_Code" )

I wanna change the value of Status from 1 => active and 0 => not active.

0

2 Answers 2

1

You can do this with the ANSI standard case statement in almost all databases:

select Machine_Code, Machine_Name,
       (case when Status = 1 then 'active' else 'not active' end) as status
from Machine_Master
where '" & combolinecode.Text & "' = Line_Code";

I fear that if you are using VBA you might be using Access, which has its own way:

select Machine_Code, Machine_Name,
       iif(Status = 1, "active", "not active") as status
from Machine_Master
where '" & combolinecode.Text & "' = Line_Code";
Sign up to request clarification or add additional context in comments.

Comments

0

You can use case :

select Machine_Code
     , Machine_Name
     , (case when Status = 1 then 'active' else 'not active' end) as Status
from Machine_Master 
where '" & combolinecode.Text & "' = Line_Code

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.