Hi
I want a query if any one of the items have "MT" value in field U_Bill and value in U_Ans <> 'Y' then it should give error
Thanks
Hi
I want a query if any one of the items have "MT" value in field U_Bill and value in U_Ans <> 'Y' then it should give error
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Aman GuptaPosted Mar 17, 2025, 9:38 AM
CREATE PROCEDURE CheckBillAndAns
AS
BEGIN
IF EXISTS (
SELECT 1
FROM your_table
WHERE U_Bill = 'MT' AND U_Ans <> 'Y'
)
BEGIN
RAISERROR('Error: One or more items have U_Bill = "MT" and U_Ans <> "Y".', 16, 1);
RETURN;
END
END
Daniel WrightPosted Mar 16, 2025, 6:01 AM
Hello! It seems like you are looking to create a SQL query that checks if any item has a "MT" value in the U_Bill field and a value other than 'Y' in the U_Ans field. If these conditions are met, you want to output an error.
To achieve this in SQL, you can use a SELECT query along with a CASE statement to identify and handle the conditions specified. Here's an example query that can help you achieve this:
In this query:
- Replace `your_table_name` with the actual name of your table where these fields are present.
- The CASE statement checks if U_Bill has a value of 'MT' and U_Ans has a value other than 'Y'. If this condition is met, it will display an error message; otherwise, it will display 'No Error'.
Please adjust the table name and fields according to your database schema. This query will help you identify items meeting the specified criteria. Let me know if you need further assistance or have any more questions!