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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Aman GuptaRank #193 · 12.4K reputationPosted Mar 17, 2025, 5:38 AM EDT
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 WrightRank #2,947 · 489 reputationPosted Mar 16, 2025, 2:01 AM EDT
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:
SELECT CASE WHEN U_Bill = 'MT' AND U_Ans <> 'Y' THEN 'Error: Invalid combination found' ELSE 'No Error' END AS Error_Status FROM your_table_name;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!