An 'IN' inside an 'IFF' gives a syntax error - sql

I cannot figure out why this is wrong. The syntax for an IFF is defined here:
https://msdn.microsoft.com/en-us/library/hh213574.aspx
Why does it complain about the IN operator?

It looks like you're using a version of SQL Server that does not support this function (pre SQL Server 2012). An alternative is to use a case statement like so:
Select NEWID(), m.MALEPUNKTYPE,
case when m.MALEPUNKTYPE in ('E17', 'E18') then 'D02' else null end
from AMALD m
This is supported from SQL Server 2005 onwards however it should work on earlier versions too

Related

SQL Query to Get DB2 Version on IBM i

I would like to find out which version of DB2 we are running on our IBM i server using only SQL SELECT.
I am executing my queries via installed ODBC drivers for i Access. The places I am executing the queries are Excel-ODBC and Excel-Microsoft Query (simply because I am not a developer and therefore don't have/don't know of another place to run queries).
The following solutions do not work for me:
How to check db2 version
Get DB2 instance name using SQL
Basic reasons why I have failed to get the above solutions to work:
I do not have a SYSPROC table/have access to SYSPROC table
SYSIBMADM table does not contain a ENV_INST_INFO table.
I think these answers may be tailored to those using IBM z, but I use IBM i.
My end goal is to be able to execute a SQL SELECT and get the version of DB2 used on our server.
Try this:
SELECT RELEASE_LEVEL, TEXT_DESCRIPTION
FROM QSYS2.SOFTWARE_PRODUCT_INFO
WHERE PRODUCT_ID = '5770SS1'
AND PRODUCT_OPTION = '27'
--or this instead of the above line:
--AND LOAD_TYPE = 'CODE' AND PRODUCT_OPTION = '*BASE'

Quickbook Online API throws Error Parsing query / trying to use CASE statement in SQL query

I am trying to get status based to totalamount field.For that I need to use CASE statement like this :
Select TotalAmt,CASE WHEN 'TotalAmt' = '0' THEN 'Open' ELSE NULL END AS status from Invoice
I have checked the syntax too,it's correct.But still I am getting query Parser error
Intuit's flavor of SQL (which is a very limited, slightly non-SQL-standard dialect of SQL) does not support CASE statements.
You can't do what you're trying to do, as it's unsupported.

searching for microsoft sql server equivalent of postgresql form

SELECT nextval('AWARD_ID')
I am getting nextval as not built in function name in MS SQL Server. Kindly give any alternative if there is any.
It seems you are looking for SELECT NEXT VALUE FOR award_id.
Do you mean something like IDENT_CURRENT():
select IDENT_CURRENT('FOO') + IDENT_INCR('FOO')

SQL Server 2000 Regular Expression alternative

I wrote a stored procedure which on several declared variables uses regular expression.
Example:
IF #value_criteria like '%[^0-9]%'
SET #having_clause = 'HAVING value_criteria <=' + #value_criteria
....to my latter disappointment it runs on SQL Server 2000 which does not seem to "know" reg. ex. (unless extra DLL is installed which I cannot do.)
Is there an alternative to this statement which would work for SQL Server 2000 ?
Thanks
Your expression:
IF #value_criteria like '%[^0-9]%'
SET #having_clause = 'HAVING value_criteria <=' + #value_criteria;
is standard like syntax (for SQL Server). This structure for the pattern is support in SQL Server 2000. It does not require regular expressions.
The SQL Server 2000 documentation for like explains the support for this type of pattern.

What's wrong with this query?

using MySQL version 4.0.27:
UPDATE `t` SET `col_x` =
(SELECT `col_x` FROM `t` WHERE `col_y`='123456') WHERE `col_y`= '456789'
Error message: #1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT t FROM b WHERE col_x='1234
I tried LIKE '%123456%'
I'm sorry to disappoint you, but subqueries are not supported in your version if MySQL.
Subqueries have been introduced in ver 4.1 according to MySQL Dev Zone
You can't select and update from the same table in a query.
reference: mysql update documentation
Check out this page. Apparently you need to set your SQL mode to 'ANSI QUOTES'