October 22, 2022 at 8:38 pm
I am working with SQL Server and needed some help with a query
When you run this "SELECT 'YES' it would print Yes in column 1 Row 1, I want to print a dynamic list, so it doesn't look at a existing table. So if criteria 1 is met it would print YES/NO/Maybe and if it meets criteria 2 then its 100/50/25, as I said it wouldn't be a existing table. it would print a new table. This would have to be done without using any create functions. Just with SELECT.
October 22, 2022 at 9:37 pm
Ok... so what is "Criteria 1" and "Criteria 2" to return 1 value or another?
--Jeff Moden
Change is inevitable... Change for the better is not.
October 23, 2022 at 1:10 am
So yeah, criteria meaning a condition. So if condition one is met then it would be list 1, else list 2.
October 23, 2022 at 7:05 am
SELECT ListValue,...
FROM <table>
WHERE ListNumber = @ListNumber ;
So the table would be something like
CREATE TABLE ListValue (ListNumber INT, ListValue VARCHAR(10));
GO
INSERT INTO ListValue VALUES(1, 'A'),(1,'B'), (2,'C'),(2,'D');
October 23, 2022 at 2:33 pm
Is there any way to do it without inserting data? with case statements? I pretty much need it to print like the above table but on the fly.
Something like this
SELECT "Yes" & "No"
Table 1
YES
NO
October 23, 2022 at 8:08 pm
In SELECT statements the FROM clause and JOINs are evaluated first. Maybe you could use the VALUES table value constructor to store (rows of) criteria, order number, and value. Then use a WHERE clause to filter the results
/* criteria = YES/NO (comment/uncomment) */
declare @criteria varchar(10)='Yes';
--declare @criteria varchar(10)='No';
select v.col_value
from (values ('No', 1, '100'),
('No', 2, '50'),
('No', 3, '25'),
('Yes', 1, 'Yes'),
('Yes', 2, 'No'),
('Yes', 3, 'Maybe'))
v(criteria, order_num, col_value)
where v.criteria=@criteria
order by v.order_num;
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
October 24, 2022 at 2:40 am
So I saw a while back that its possible with a case statement, because once this sql code is created it goes into a another software that parses basic level of sql. So I'm trying to figure it out and find that article but can't find it for the death of me.
October 24, 2022 at 1:25 pm
So I saw a while back that its possible with a case statement, because once this sql code is created it goes into a another software that parses basic level of sql. So I'm trying to figure it out and find that article but can't find it for the death of me.
Your descriptions haven't helped me help you. I understand what criteria does... I'm just not bagging what you're raking in your problem description. For example, the words "Yes", "No', and "Maybe" aren't "criteria" to me. They the results of applying criteria.
So, with that, can you provide a specific example instead of the extremely generic 100,000 foot level descriptions that you've been using?
--Jeff Moden
Change is inevitable... Change for the better is not.
October 24, 2022 at 1:35 pm
Considering there's something urgent going on, why not tell us exactly what it is that you're trying to do and then we might be able to better help. All these vague hints at what's going on mean we're guessing.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
October 24, 2022 at 1:39 pm
Considering there's something urgent going on, why not tell us exactly what it is that you're trying to do and then we might be able to better help. All these vague hints at what's going on mean we're guessing.
I think the homework submission date has now past.
October 24, 2022 at 2:13 pm
Is there a way to create this output without using insert into and declaring anything.
Lets forget all the conditions. Lets just say that I need to print this without using tables and declaring values.
When you run this SQL "SELECT "YES", it would print this. I need it display the image above using just the select and case statement if possible.
October 24, 2022 at 2:44 pm
Yes... Steve Collins posted an example above. You could also use multiple SELECTs with a UNION ALL.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 25, 2022 at 7:08 pm
Is there a way to create this output without using insert into and declaring anything.
Lets forget all the conditions. Lets just say that I need to print this without using tables and declaring values.
When you run this SQL "SELECT "YES", it would print this. I need it display the image above using just the select and case statement if possible.
To make this as simple as possible:
Of course, you need to define <some condition>. There is also Steve's example...
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
March 7, 2023 at 4:43 pm
This was removed by the editor as SPAM
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply