I have the following problem:
I'd like to use a specific query depending what number a user has set in Firebird SQL, so in pseudo code:
IF (TABLENAME.USERFLAG <> 5 WHERE TABLENAME.USER = 15555) THEN
EXECUTE QUERY 1
ELSE
EXECUTE QUERY 2
The problem is, that does not seem to work. What could I do to get it working?
Related
At work I saw I saw a SQL query in Teradata that had the following:
CASE WHEN (sp_ce / ‘0000001000000000’XI8) MOD 2 = 1 THEN ‘Y’ ELSE ‘N’ END AS res_p
What is the meaning of XI8? What is it doing to the number string?
Also when I tried to run this in Big Query it’s not supported, it errors out with
Syntax error: Unexpected identifier \XI8\
How would I write that case statement in big query?
Using MOD on big query without the numbers as a string and without the XI8 yields different results.
Thank you
So I am trying to figure out how to fail a SQL statement incase the case - when statement is not met.
I have been doing some searching and didn't find anything useful
this is the query for example ..
select
case when 1 = 1 then 'ok'
else < what to write here?>
end
If I am writing a typo or something like that this will fail the query entirely for syntax even if the condition is met .
Hope I could use your help !
SQL Server does not seem to support selecting Boolean result.
Example:
Select True;
Or
Select 1>2;
would return an Error.
However, in the majority of programming languages a similar operation is valid. Is there a reason for that?
SQL is not designed for deductive statements. however you can achieve similar results using a statement like this:
SELECT CASE WHEN 2 > 1 THEN 1 ELSE 0 END
I'm having some trouble understanding WHY a select statement isn't working in a query I'm making.
I've got the SELECT and FROM lines functioning. With just those, ALL results from my selected table are displayed - 517 or so
What I want to do is display results based on a pattern using LIKE - What I have so far
SELECT *
FROM Tbl_ServiceRequestMatrix
WHERE Tbl_ServiceRequestMatrix.[Application/Form] LIKE 'P%';
This returns 0 results - despite the fact that the column selected DOES have entries that start with 'P'
I also tried utilising brackets, see if that was the issue - still displays 0 results:
SELECT *
FROM Tbl_ServiceRequestMatrix
WHERE ((Tbl_ServiceRequestMatrix.[Application/Form])='p%');
Can any one help me understand why my WHERE ** LIKE statement is causing 0 results to be displayed?
The wildcard character in MS Access is (by default) * instead of %:
WHERE Tbl_ServiceRequestMatrix.[Application/Form] LIKE "P*"
LIKE Statement has different parameters in different sql languages.
In MS Access you need * Instead of % in LIKE Statement.
In most RDBMS:es, this work:
select (5 > 3)
and evaluates to true. It doesn't work in MS Transact SQL and the only workaround I've found is to write:
select case when 5 > 3 then 1 else 0 end
Which kind of sucks because it is much more verbose. Is there a better way to write the above kind of checks?
If the problem is arithmetic comparison:
select (5 - 3)
Then at the application level test for < or = or > 0.
You could write it as a scalar-valued function, but it will be very slow on large datasets.
If your program often requires such case constructs you could create your set of functions that will have user functions like Bool_IsGreater(left, right) that will return you your desired 0 or 1.
SQL Server doesn't support boolean value type anyway even for basic column use.
If you will need performance and those 5 and 3 values come naturally from some select query you might want to create a new column and set its value to 1 or 0 by trigger or something, which could help with performance.