Expression not working in MS SQL server [closed] - sql-server

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

Related

Query has no result even parameter was copied for other query result [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have database with collation Chinese_Taiwan_Stroke_BIN . On my first query, I was able to successfully get a result expected
Select project_name where project_id='LOC0001'
with result 'Location 凱滙 第'
But when I copy and paste the result on my next query
select project_id where project_name='Location 凱滙 第'
this yields to no result.
Upon checking, the issue is with this specific character '滙'
because when I use 'where project_name like 'Location 凱%', it will show result
but when I use 'where project_name like 'Location 凱滙%', it has no result
The character '滙' is an Unicode character that why you need to insert prefix 'N'.Any time you pass Unicode data to SQL Server you must prefix the Unicode string with N
select project_id where project_name LIKE N'Location 凱滙%'

Combining both OR and AND in clause query SQL server [closed]

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 3 years ago.
Improve this question
I want to select data from a table with clause involving AND and OR.
Here is my sql query:
select *
from WORKTR
where status='Active' OR status='Inactive'and Start_date='2020-02-10'
However, the query above only return 3 from 10 rows in the table which means it does not return the all of the rows that obey the conditions. Please help me to show the right way to write the query.
You should wrap your condition correctly like below
where status='Active' OR (status='Inactive' and Start_date='2020-02-10')
Add parenthesis, according to your needs
select *
from WORKTR
where (status='Active' OR status='Inactive)'and Start_date='2020-02-10'
OR
select *
from WORKTR
where status='Active' OR (status='Inactive'and Start_date='2020-02-10')
OR
select *
from WORKTR
where status IN ('Active','Inactive') and Start_date='2020-02-10'

embedded sql in c,how to check if records exist [closed]

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)...

SQL Server : CASE statement inside stuff function [closed]

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')

SQL - need to return a value of 0 or 1 based on items in a list [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Based on the type of employee in a table I need to return a 0 or 1 to then be output to specific spot in a file
For EXB return 1 for all other types FTR, FTRG, PTRG and SALR return 0.
select case when type = 'EXB' then 1 else 0 end
from employee
Use case <column> when 'EXB' then 1 else 0 end as shown in the SQL Fiddle to select values in the expression query.
Alternately, use a lookup table to map from your codes to the numeric values.
Then use one of the XML modifiers in the query to return an xml fragment.

Resources