decode(BITAND(Col,1),1,'D','')|| decode(BITAND(Col,2),2,'d','')|| decode(BITAND(Col,4),4,'B','')|| decode(BITAND(Col,8),8,'b','')||
How i can Cast the above condition in teradata.
Thanks in advance!!
I don't believe there is a 1:1 DECODE() equivalent in Teradata. You will probably need to use a CASE statement instead:
CASE WHEN BITAND(col,1)=1 THEN 'D' END || CASE WHEN BITAND(col,2)=2 THEN 'd' END || CASE WHEN BITAND(Col,4)=4 THEN 'B' END || CASE WHEN BITAND(Col,8)=8 THEN 'b' END
Related
I have this CASE statement that I need to convert to IIF in Access:
Case When sfrstcr_pidm is not null Then 'A' WHen sfrstcr_pidm <> '' Then 'A' Else Null End as StudentStatus,
Would this be the correct way to convert to IIF?
IIF ([sfrstcr_pidm] is not null, ‘A’, IIF([sfrstcr_pidm] <> ‘’, ‘A’, Null))
The most obvious way to convert a Case statement to Access SQL is using the Switch function. This takes multiple arguments, and uses if ... then ... elseif ... logic. It doesn't have an else option, but elseif true works around that.
Using this function, your code would become the following:
Switch(sfrstcr_pidm is not null, 'A', sfrstcr_pidm <> '', 'A', True, Null)
can someone help with that.
I need to check against a column say, "COL_A" that if its not null and is numeric (10,0).
Need to check and find the rows that are not null and are numeric (10,0).
Please help
You should create a function to validate the number and use a NVL function to Null validation:
Code To function:
CREATE OR REPLACE FUNCTION isNumeric(strVal IN VARCHAR2)
RETURN VARCHAR2 DETERMINISTIC PARALLEL_ENABLE
IS
numericVal NUMBER;
BEGIN
numericVal := to_number(strVal);
RETURN 'True';
EXCEPTION
WHEN value_error THEN
RETURN 'False';
END isNumeric;
Code to call the function:
SELECT DECODE(isNumeric(NVL("COL_A", 'null')) = 'True', "COL_A", 0) AS "valor"
FROM myTable
The answer above is probably the best response. If you wanted to use SQL instead of PL/SQL, the following should work:
SELECT col_a
FROM mytable
WHERE regexp_like( col_a, '^[[:digit:]]*$' );
If you are using PL/SQL and need to process records in a loop:
DECLARE
CURSOR mycur IS
SELECT col_a
FROM mytable
WHERE regexp_like(col_a, '^[[:digit:]]*$');
BEGIN
FOR myrec IN mycur LOOP
DBMS_OUTPUT.PUT_LINE(col_a);
END LOOP;
END;
i simply have two fields. dtStartTime and dtStartDate.
I want to do a query now which returns one combined field dtStart using SQLite
I have tried
SELECT (dtStartDate+dtStartTime) as dtStart1, from ...
but it returns wrong values...
Thank you, shorty
PS: Dates are stored as unixepoch
SELECT datetime(d, t)
FROM (
SELECT date('now') as d, time('now') as t) as dt;
probably:
SELECT DATETIME(DATE(dtStartDate) || ' ' || TIME(dtStartTime)) FROM YourTable;
I am using a not equal operator <> in my sql statement but it doesn't retrieve any record which is not equal to the selected date.
CODE:
Command = New SqlCommand("SELECT * FROM [Products] WHERE [ParkingStartDate] <> #StartDate", myConn)
Command.Parameters.AddWithValue("#StartDate", StartDate1)
This won't return anything if either of the following is true:
StartDate1 is a NULL
ParkingStartDate for all values is a NULL or equal to StartDate1 (obvious one)
Check that you are passing a non-NULL value in StartDate1 and there are records satisfying your condition.
If the values are null you would have to do
Command = New SqlCommand("SELECT * FROM [Products] WHERE [ParkingStartDate] <> #StartDate OR ParkingStartDate is null", myConn)
Command.Parameters.AddWithValue("#StartDate", StartDate1)
First stop using that <> operator.
Use instead != (NOT EQUAL)
run this statement in sql. it will return zero results. to illustrate my point.
select '1' where NULL <> 0
instead use
where columname != #startdate or columnname is null
One important thing to take into consideration when dealing with querying based on date is that the date in SQL Server is treated as exact as the date you send in. So, if you pass in a full date/time, like 2011-10-24 14:35:29, it will return all dates that are not that exact date. If you are looking for a particular portion of that date to be selected against, you need to only give that portion of the date. Using the DATEPART command will help here also.
If the value is undefined, it is not included in <> or != clause.
Along with these you can use sql function 'COALESCE()' to include rows having undefined cells.
"SELECT * FROM [Products] WHERE COALESCE([ParkingStartDate],'') <> #StartDate OR ParkingStartDate is null"
Hope it will help you.
My recommendation would be to try with NULLIF operator. Modify your query to be like :
SELECT * FROM [Products] WHERE NULLIF([ParkingStartDate], #StartDate) IS NOT NULL OR ParkingStartDate is NULL
Hope this helps.
I have to execute a statement like ( i need and keyword along with when ).
select
'Is Allowed'= case A.Column
when
A.Column='XXXX' and Isnull(A.AnotherColumn,'')<>'' then 'Yes'
else
'No' end from TableName
I am getting syntax error,how to rewrite it without affecting the condition.
Try:
select case when A.Column='XXXX' and Isnull(A.AnotherColumn,'')<>'' then 'Yes'
else 'No' end as 'Is Allowed'
from TableName
SELECT
CASE A.Column
WHEN 'Is Allowed THEN 'First'
WHEN 2 THEN 'Second'
WHEN 3 THEN 'Third'
ELSE 'Other'
END
Is the general way of making a CASE (which is your question). However, your query/logic looks a bit convoluted. More detailed answer / query is possible, but would perhaps use more statements/ nested CASE.
Have a closer look at CASE (Transact-SQL)
SELECT CASE
WHEN some boolean expression
THEN value
ELSE default value
END
or
SELECT CASE value to check
WHEN vlue to check agains
THEN value
ELSE default value
END