Replace the values that are returned from a SQL query
I have the following query:
SELECT
BM.BOOKING_NO,
BM.REF,
BM.ACCOUNT,
BM.NAME,
BM.STATUS,
BM.DATE_IN,
BM.DATE_OUT,
BM.TOTNIGHTS,
BM.ROOM_NO,
BM.TOTFRGN,
REC.PRICE_CATAGORY
FROM
BOOKMASTER BM LEFT JOIN RECEIVABLES REC ON BM.ACCOUNT = REC.ACCOUNT_NO
WHERE
BM.STATUS = 'CHECK IN'
The REC.PRICE_CATAGORY column will return one of three values: 1, 2 or 3.
I want to replace it with the following values:
- If
1, I want it to read'YES' - If
2, I want it to read'NO' - If
3, I want it to read'MAYBE'
My results return to an Excel spreadsheet and so the lazy way would be to do a VLOOKUP, but I would prefer to do it inside the query.
I feel like this is a job for a CASE statement, but I am not 100% sure how to construct the query
Any help will be appreciated.
sql excel odbc
add a comment |
I have the following query:
SELECT
BM.BOOKING_NO,
BM.REF,
BM.ACCOUNT,
BM.NAME,
BM.STATUS,
BM.DATE_IN,
BM.DATE_OUT,
BM.TOTNIGHTS,
BM.ROOM_NO,
BM.TOTFRGN,
REC.PRICE_CATAGORY
FROM
BOOKMASTER BM LEFT JOIN RECEIVABLES REC ON BM.ACCOUNT = REC.ACCOUNT_NO
WHERE
BM.STATUS = 'CHECK IN'
The REC.PRICE_CATAGORY column will return one of three values: 1, 2 or 3.
I want to replace it with the following values:
- If
1, I want it to read'YES' - If
2, I want it to read'NO' - If
3, I want it to read'MAYBE'
My results return to an Excel spreadsheet and so the lazy way would be to do a VLOOKUP, but I would prefer to do it inside the query.
I feel like this is a job for a CASE statement, but I am not 100% sure how to construct the query
Any help will be appreciated.
sql excel odbc
add a comment |
I have the following query:
SELECT
BM.BOOKING_NO,
BM.REF,
BM.ACCOUNT,
BM.NAME,
BM.STATUS,
BM.DATE_IN,
BM.DATE_OUT,
BM.TOTNIGHTS,
BM.ROOM_NO,
BM.TOTFRGN,
REC.PRICE_CATAGORY
FROM
BOOKMASTER BM LEFT JOIN RECEIVABLES REC ON BM.ACCOUNT = REC.ACCOUNT_NO
WHERE
BM.STATUS = 'CHECK IN'
The REC.PRICE_CATAGORY column will return one of three values: 1, 2 or 3.
I want to replace it with the following values:
- If
1, I want it to read'YES' - If
2, I want it to read'NO' - If
3, I want it to read'MAYBE'
My results return to an Excel spreadsheet and so the lazy way would be to do a VLOOKUP, but I would prefer to do it inside the query.
I feel like this is a job for a CASE statement, but I am not 100% sure how to construct the query
Any help will be appreciated.
sql excel odbc
I have the following query:
SELECT
BM.BOOKING_NO,
BM.REF,
BM.ACCOUNT,
BM.NAME,
BM.STATUS,
BM.DATE_IN,
BM.DATE_OUT,
BM.TOTNIGHTS,
BM.ROOM_NO,
BM.TOTFRGN,
REC.PRICE_CATAGORY
FROM
BOOKMASTER BM LEFT JOIN RECEIVABLES REC ON BM.ACCOUNT = REC.ACCOUNT_NO
WHERE
BM.STATUS = 'CHECK IN'
The REC.PRICE_CATAGORY column will return one of three values: 1, 2 or 3.
I want to replace it with the following values:
- If
1, I want it to read'YES' - If
2, I want it to read'NO' - If
3, I want it to read'MAYBE'
My results return to an Excel spreadsheet and so the lazy way would be to do a VLOOKUP, but I would prefer to do it inside the query.
I feel like this is a job for a CASE statement, but I am not 100% sure how to construct the query
Any help will be appreciated.
sql excel odbc
sql excel odbc
edited Nov 12 at 18:50
Lee Mac
3,45631339
3,45631339
asked Nov 12 at 18:43
gdekoker
102
102
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You did the 50 % in the question itself by mentioning case expression , but you don't know the implementation so, you can do :
SELECT BM.BOOKING_NO, BM.REF, BM.ACCOUNT, BM.NAME, BM.STATUS, BM.DATE_IN, BM.DATE_OUT, BM.TOTNIGHTS, BM.ROOM_NO, BM.TOTFRGN,
(CASE REC.PRICE_CATAGORY
WHEN 1 THEN 'YES'
WHEN 2 THEN 'NO'
WHEN 3 THEN 'MAYBE'
ELSE 'Whatever you want to print'
END) AS PRICE_CATAGORY
FROM BOOKMASTER BM LEFT JOIN
RECEIVABLES REC
ON BM.ACCOUNT = REC.ACCOUNT_NO
WHERE BM.STATUS = 'CHECK IN';
thank you, that worked perfectly
– gdekoker
Nov 12 at 18:51
add a comment |
If you want the column as string values, then:
SELECT id, name, CASE WHEN hide = 0 THEN 'false' ELSE 'true' END AS hide
FROM anonymous_table
If the DBMS supports BOOLEAN, you can use instead:
SELECT id, name, CASE WHEN hide = 0 THEN false ELSE true END AS hide
FROM anonymous_table
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268259%2freplace-the-values-that-are-returned-from-a-sql-query%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You did the 50 % in the question itself by mentioning case expression , but you don't know the implementation so, you can do :
SELECT BM.BOOKING_NO, BM.REF, BM.ACCOUNT, BM.NAME, BM.STATUS, BM.DATE_IN, BM.DATE_OUT, BM.TOTNIGHTS, BM.ROOM_NO, BM.TOTFRGN,
(CASE REC.PRICE_CATAGORY
WHEN 1 THEN 'YES'
WHEN 2 THEN 'NO'
WHEN 3 THEN 'MAYBE'
ELSE 'Whatever you want to print'
END) AS PRICE_CATAGORY
FROM BOOKMASTER BM LEFT JOIN
RECEIVABLES REC
ON BM.ACCOUNT = REC.ACCOUNT_NO
WHERE BM.STATUS = 'CHECK IN';
thank you, that worked perfectly
– gdekoker
Nov 12 at 18:51
add a comment |
You did the 50 % in the question itself by mentioning case expression , but you don't know the implementation so, you can do :
SELECT BM.BOOKING_NO, BM.REF, BM.ACCOUNT, BM.NAME, BM.STATUS, BM.DATE_IN, BM.DATE_OUT, BM.TOTNIGHTS, BM.ROOM_NO, BM.TOTFRGN,
(CASE REC.PRICE_CATAGORY
WHEN 1 THEN 'YES'
WHEN 2 THEN 'NO'
WHEN 3 THEN 'MAYBE'
ELSE 'Whatever you want to print'
END) AS PRICE_CATAGORY
FROM BOOKMASTER BM LEFT JOIN
RECEIVABLES REC
ON BM.ACCOUNT = REC.ACCOUNT_NO
WHERE BM.STATUS = 'CHECK IN';
thank you, that worked perfectly
– gdekoker
Nov 12 at 18:51
add a comment |
You did the 50 % in the question itself by mentioning case expression , but you don't know the implementation so, you can do :
SELECT BM.BOOKING_NO, BM.REF, BM.ACCOUNT, BM.NAME, BM.STATUS, BM.DATE_IN, BM.DATE_OUT, BM.TOTNIGHTS, BM.ROOM_NO, BM.TOTFRGN,
(CASE REC.PRICE_CATAGORY
WHEN 1 THEN 'YES'
WHEN 2 THEN 'NO'
WHEN 3 THEN 'MAYBE'
ELSE 'Whatever you want to print'
END) AS PRICE_CATAGORY
FROM BOOKMASTER BM LEFT JOIN
RECEIVABLES REC
ON BM.ACCOUNT = REC.ACCOUNT_NO
WHERE BM.STATUS = 'CHECK IN';
You did the 50 % in the question itself by mentioning case expression , but you don't know the implementation so, you can do :
SELECT BM.BOOKING_NO, BM.REF, BM.ACCOUNT, BM.NAME, BM.STATUS, BM.DATE_IN, BM.DATE_OUT, BM.TOTNIGHTS, BM.ROOM_NO, BM.TOTFRGN,
(CASE REC.PRICE_CATAGORY
WHEN 1 THEN 'YES'
WHEN 2 THEN 'NO'
WHEN 3 THEN 'MAYBE'
ELSE 'Whatever you want to print'
END) AS PRICE_CATAGORY
FROM BOOKMASTER BM LEFT JOIN
RECEIVABLES REC
ON BM.ACCOUNT = REC.ACCOUNT_NO
WHERE BM.STATUS = 'CHECK IN';
answered Nov 12 at 18:48
Yogesh Sharma
28.2k51335
28.2k51335
thank you, that worked perfectly
– gdekoker
Nov 12 at 18:51
add a comment |
thank you, that worked perfectly
– gdekoker
Nov 12 at 18:51
thank you, that worked perfectly
– gdekoker
Nov 12 at 18:51
thank you, that worked perfectly
– gdekoker
Nov 12 at 18:51
add a comment |
If you want the column as string values, then:
SELECT id, name, CASE WHEN hide = 0 THEN 'false' ELSE 'true' END AS hide
FROM anonymous_table
If the DBMS supports BOOLEAN, you can use instead:
SELECT id, name, CASE WHEN hide = 0 THEN false ELSE true END AS hide
FROM anonymous_table
add a comment |
If you want the column as string values, then:
SELECT id, name, CASE WHEN hide = 0 THEN 'false' ELSE 'true' END AS hide
FROM anonymous_table
If the DBMS supports BOOLEAN, you can use instead:
SELECT id, name, CASE WHEN hide = 0 THEN false ELSE true END AS hide
FROM anonymous_table
add a comment |
If you want the column as string values, then:
SELECT id, name, CASE WHEN hide = 0 THEN 'false' ELSE 'true' END AS hide
FROM anonymous_table
If the DBMS supports BOOLEAN, you can use instead:
SELECT id, name, CASE WHEN hide = 0 THEN false ELSE true END AS hide
FROM anonymous_table
If you want the column as string values, then:
SELECT id, name, CASE WHEN hide = 0 THEN 'false' ELSE 'true' END AS hide
FROM anonymous_table
If the DBMS supports BOOLEAN, you can use instead:
SELECT id, name, CASE WHEN hide = 0 THEN false ELSE true END AS hide
FROM anonymous_table
answered Nov 12 at 18:59
Ammar Iqbal
213
213
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268259%2freplace-the-values-that-are-returned-from-a-sql-query%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown