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
Can i use nested Case statements in t-sql as i have done and also "*" used for multiplcation in the access query can it be used in the same way in T-sql for example
([Col2]*[col3])
MS Access:
IIf(IsNull([Col1]),([Col2]*[col3]),([col2]*[col3]/[col1])) as Column
T-Sql:
Case When [Col1] Is Null then ([Col2]*[col3])
else ([col2]*[col3]/[col1]) end AS column
Ms Access:
IIf(Left([col],1)=3,"Tran",IIf(Left([ss],1)=7,"Con","Sto")) AS [col]
T-sql:
(Case When (Left([col],1)=3) then 'Tran' else (Case When (Left([col],1)=7) then 'Con' else 'Sto' end )end) AS [col type]
Your 2nd TSQ should look like this:
CASE
WHEN LEFT([col],1)=3 THEN 'Tran'
WHEN LEFT([col],1)=7 THEN 'Con'
ELSE 'Sto'
END AS [col type]
As far as # you don't need that in SQL, just put the date value in single quotes correctly formatted.
Related
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 months ago.
Improve this question
can anyone tell me why I can not run this code in SQL Management studio?
Thanks in advance.
SELECT * FROM TabKontaktJednani
where
TabKontaktJednani.Typ IN (
CASE 'ERP'--(SELECT ALIAS FROM TabCisZam where LoginId = SUSER_NAME())
WHEN 'ERP'
THEN ('HeO','OST')
WHEN 'TO'
THEN ('SW','OST')
END)
The reason you can't run that code is that CASE expressions can only return one scalar value, not a list of values.
Your CASE expression returns a tuple. That is not allowed in SQL. But as MySQL supports a boolean data type, a CASE expression may result in a boolean:
SELECT *
FROM tabkontaktjednani
WHERE
CASE (SELECT alias FROM tabciszam WHERE loginid = suser_name())
WHEN 'ERP' THEN typ IN ('HeO', 'OST')
WHEN 'TO' THEN typ IN ('SW', 'OST')
END;
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 1 year ago.
Improve this question
I have a table in SQL Server where a row contains a Json column - something like this:
ResponseText
RequestId
{"LosUnqCod":0,"LosMidId":23}
96173722
{"LosUnqCod":1,"LosMidId":5}
96173721
I want to have a table in this shape:
LosUnqCod
LosMidId
RequestId
0
23
96173722
1
5
96173721
how to open this json?
Hi every body I found my answer and want to share with anyone who has the same issue as I does
SELECT
reqTbl.LosUnqCod ,
a.RequestId
FROM [dbo].[a] CROSS APPLY
OPENJSON( dbo.a.responsetext)
WITH (
LosUnqCod nvarchar(50)
) AS reqTbl
You don't have to use OPENJSON if you only have one JSON object (not an array) per SQL row, you can use JSON_VALUE instead:
SELECT
JSON_VALUE(a.responsetext, '$.LosUnqCod') LosUnqCod,
JSON_VALUE(a.responsetext, '$.LosMidId') LosMidId,
a.RequestId
FROM [dbo].[a];
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 1 year ago.
The community reviewed whether to reopen this question 11 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
i have a database (mysql) with links like:
mysite.com/Movies/Abajan_1080p.mp4
mysite.com/Movies/Abajan_720p.mp4
mysite.com/Movies/Abajan_480p.mp4
mysite.com/Movies/Bahman_1080p.mp4
mysite.com/Movies/Bahman_720p.mp4
mysite.com/Movies/Bahman_480p.mp4
....
i sorted my files by creating directories by alphabets (A,B,...)
so i need to change links:
mysite.com/Movies/A/Abajan_1080p.mp4
mysite.com/Movies/A/Abajan_720p.mp4
mysite.com/Movies/A/Abajan_480p.mp4
mysite.com/Movies/B/Bahman_1080p.mp4
mysite.com/Movies/B/Bahman_720p.mp4
mysite.com/Movies/B/Bahman_480p.mp4
is there a simple solution to edit database? to edit all links like that?
Thanks a lot
You can use the function SUBSTRING_INDEX() to get the filename and then concatenate the path:
UPDATE tablename
SET col = CONCAT(
'mysite.com/Movies/',
LEFT(SUBSTRING_INDEX(col, '/', -1), 1),
'/',
SUBSTRING_INDEX(col, '/', -1)
)
Replace col with your column's name.
See the demo.
Results:
col
mysite.com/Movies/A/Abajan_1080p.mp4
mysite.com/Movies/A/Abajan_720p.mp4
mysite.com/Movies/A/Abajan_480p.mp4
mysite.com/Movies/B/Bahman_1080p.mp4
mysite.com/Movies/B/Bahman_720p.mp4
mysite.com/Movies/B/Bahman_480p.mp4
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 2 years ago.
Improve this question
I'd like a MySQL query to achieve the following :
I have 10000 rows that look like this
Source 1::https://domainxyz.com//public/dist/s2q1sd65az7r/index.html||Source 2::https://domainabc.com/embed-8eel8v83lefs.html||Source 3::https://domainqsd.com/v/w1qy8g81w6||Source 5:://domainwxc.com/embed2.php?link=5fUE7Mo%25
Only the links are different from one row to another
I'd like to remove all content related to Source 1
That content would be anything between "Source 1" and "||" (including the removal of the string "source 1")
So in my exemple, that would removing this :
Source 1::https://domainxyz.com//public/dist/index.html
PS : it also possible that "Source 1" data has no "||" at the end (when the data is at the end of the ligne)
You can use regexp_replace():
select regexp_replace(concat(str, '||'), 'Source 1::[^|]*[|][|]', '')
from (select 'Source 1::https://domainxyz.com//public/dist/s2q1sd65az7r/index.html||Source 2::https://domainabc.com/embed-8eel8v83lefs.html||Source 3::https://domainqsd.com/v/w1qy8g81w6||Source 5:://domainwxc.com/embed2.php?link=5fUE7Mo%25' as str
) t
Or alternatively as:
select regexp_replace(str, 'Source 1::[^|]*([|][|]|$)', '')
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
In my database table have this value,i have to check this email value 'abc#gmail.com' is exist in the database or not.
abc#gmail.com
edf#dfg.com
xyz#abcinfo.com
12345#fdfg.com
If 'abc#gmail.com' value is exist in the database table, output is true else false, so how to write the query for this to achieve?
thanks
Kumar
You can do something as simple as
select CASE WHEN count(1) > 0 THEN 'true' ELSE 'false' END from table where email = 'abc#gmail.com'
But you should give some more information for a beater answer.
you can write query like
SELECT IF(COUNT(*) >0, TRUE,FALSE)as response FROM <tablename> WHERE emailid='edf#dfg.com';
select exists(
SELECT 1 FROM <tableName> WHERE email LIKE 'abc#gmail.com'
)