Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a question about SQL Server's IF clause.
For example - look at this code:
IF (#logpath IS NOT NULL || #ptd IS NOT NULL)
Can I use || in the condition when I use IF statement?
Is this correct?
|| is not valid Transact-SQL syntax. You need to user 'OR' or 'AND'
Example
IF #logpath is not null OR #ptd is not null
BEGIN
-- do something
END
You cannot use the || operator in SQL Server. Please refer the following link which shows the list of logical operators in SQL Server
http://msdn.microsoft.com/en-us/library/ms189773.aspx
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I m trying to convert oracle to snowflake
HASH(NAME CONCAT '#'
CONCAT Address CONCAT '#'
CONCAT DECODE(phone,'true','Y','N') CONCAT '#'
CONCAT column_name, 123456) hash_key
Can anyone please help me here.
Try:
SELECT HASH(NAME || '#'
|| ADDRESS || '#'
|| DECODE(PHONE,'true','Y','N')
|| '#' || COLUMN_NAME
) AS HASH_KEY
Check the documentation for specifics on hash functions and variations on the concatenation function.
https://docs.snowflake.com/en/sql-reference/functions/hash.html
https://docs.snowflake.com/en/sql-reference/functions/concat.html
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have tried these:
1.if (EXEC SQL EXIST SELECT ...)
2.EXEC SQL IF EXIST SELECT ...
but none of these work,any help?
Select the count and check whether it is zero. Something along this line:
int a;
EXEC SQL SELECT count(*) INTO :a
FROM some_table
WHERE some_condition;
if (a != 0)...
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Is it possible to use case statement inside stuff function with for xml path() ?
Yes you can use a 'CASEstatement insideSTUFFwhen usingFOR XML PATH`
SELECT STUFF('alpha',3,5,CASE WHEN 1=1 THEN 'a' ELSE 'b' END) FOR XML PATH('test')
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Below is the expression it is used to concatenate but for some reason the result is giving just first two letter of each string. I'm little confuse what's wrong with it. Below expression is working fine in sybase but not in sql server.Thank you
Example:
F
G
Required Output:
For Young Musicians Program
GV- Record Sheet.
IF(ISNULL(fd_m_an_report),'', fd_m_an_report ) +
IF((NOT ISNULL(fd_m_an_report)) AND (NOT ISNULL(fd_m_comment)), '~r~n~r~n', '') +
IF(ISNULL(fd_m_comment ),'', fd_m_comment)
This looks like you are using Excel functions. To get something similar in SQL Server syntax you need:
select
ISNULL(fd_m_an_report,'') +
case when fd_m_an_report + fd_m_comment is null then '' else '~r~n~r~n' end +
ISNULL(fd_m_comment,'')
from MyTable
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have an XML string stored in SQL. The program that inserts the XML doesn't tag all the objects inside.
Example of string:
<XMLInfo Sample1="1234" Sample2="1234" Sample3="1234" Sample4="1234" />
I need to delete the sample2 item completely. Other things complicating this is that Sample2 may not be followed by sample3 every time and sample2 does not have a fixed length.
SQL Server:
update test set data.modify('delete XMLInfo/#Sample2');
sql fiddle demo
PostgreSQL (I think there's no xml parsing/modifying functions, but there extensions):
create or replace function remove_attrib(data xml, attr text)
returns xml
as
$$
import xml.etree.ElementTree as ET
r = ET.fromstring(data)
del r.attrib[attr]
return ET.tostring(r)
$$ language plpython3u;
update test set data = remove_attrib(data, 'Sample2');