difference between like and = [duplicate] - sql

This question already has answers here:
Equals(=) vs. LIKE
(16 answers)
WHERE clause on SQL Server "Text" data type
(7 answers)
Closed 7 years ago.
what is the differences between = to like ?
thanks for help :)
by the way if it's help , the error i get is: the data types text and varchar are incompatible in the equal to operator [msg 402]
1:

Like
The LIKE operator is used to search for a specified pattern in a column.
Where
The WHERE clause is used to extract only those records that fulfill a specified criterion.
In your case the first query do not work is because no records match the criteria you are searching.

Related

How to get only part of word from column and remove everything before and after it using PostgreSQL [duplicate]

This question already has answers here:
PostgreSQL substring get string between brackets
(2 answers)
Closed 1 year ago.
I have the following details column, with varying parameters. How can I get only joblib values? "The Place of joblib is not always the same, so I may bot be able to use substring count"
date:01/12/2014--**--joblib:[snbsd]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
date:01/12/2014--**--joblib:[jinxthin]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
date:01/12/2014--**--joblib:[snbserv]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
date:01/12/2016--**--joblib:[sql12server]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
date:01/12/2015--**--joblib:[stfmbinserx]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
date:01/12/2011--**--joblib:[ftplikes]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
Desired result:
snbsd
jinxthin
snbserv
sql12server
stfmbinserx
ftplikes
Here You go:
substring(substring(var1, position('joblib:' in var1)+8), 1, position(']' in substring(var1, position('joblib:' in var1)+8))-1)
replace var1 with column name containing Your string
With below You can try it out directly on PostgreSQL:
WITH myconstants (var1) as (
values ('date:01/12/2014--**--joblib:[snbsd]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto')
)
SELECT substring(substring(var1, position('joblib:' in var1)+8), 1, position(']' in substring(var1, position('joblib:' in var1)+8))-1)
FROM myconstants

SQL Select statement how to return emoji [duplicate]

This question already has answers here:
SQL Query Where Column = '' returning Emoji characters 🎃 and 🍰
(4 answers)
Closed 3 years ago.
I currently have a query where I want to select cake:
SELECT '🍰'
But upon executing query, it gives me an output of '??'
How to output the real cake?
set as unicode using the N'' notation
SELECT N'🍰'

How to use apostrophe in SQL [duplicate]

This question already has answers here:
MySQL variable format for a "NOT IN" list of values
(3 answers)
Closed 6 years ago.
This value is in a column in a table:
'962091','962092','962093'
I try to use this in a where. First I declare a variable:
DECLARE #KPLnr varchar(100)
SET #KPLnr = CONVERT(nvarchar(max), dbo.UF_GetOption('FastecKPL')) /* here I get the values in */
If I select, I get the correct values of #KPLnr: '962091', '962092','962093', but if I try to use it in a where statement, it seems like the value is set wrong.
I get 0 results, but if I set it manually with:
WHERE c.kpl IN ('962091', '962092','962093')
I got 414 results.
So why is WHERE c.kpl IN ('962091', '962092', '962093') not equal to
WHERE c.kpl IN (#KPLnr) in my code?
When an apostrophe is stored in a text column, you need to escape it by adding an extra apostrophe:
WHERE c.kpl IN ('962091'', ''962092'',''962093')

Exclamation mark in table.column !=0 [duplicate]

This question already has answers here:
Should I use != or <> for not equal in T-SQL?
(14 answers)
Closed 6 years ago.
Using SQL Server 2008 I have a query which resembles this:
SELECT *
FROM myTable mt
WHERE mt.ID !=0
What is the !=0 ? It looks like it's the same as saying <> 0.
I am unable to google this, is this in fact the same? A link to some documentation would be appreciated.
It is exactly the same operator as <>.
See MSDN for reference.
This is the C convention for "not equal". There is another C convention for "equal" that looks like ==.

Round And Show To 2 Decimal Places? [duplicate]

This question already has answers here:
Rounding off to two decimal places in SQL
(16 answers)
Formatting an SQL numeric query result with an arbitrary number of decimal places
(6 answers)
Closed 8 years ago.
I have a small question to ask. How to round a numeric field upto 2 decimal places, and also show it with 2 decimal places only
For example the following would return 255.88000000000
select round(255.87908765444,2)
How to get 255.88 only?
All you need is:
CAST(255.87908765444 as decimal(18,2)).
When you convert data types in which the target data type has fewer decimal places than the source data type, the value is rounded.
From microsoft
If you need it as a string, this should work:
select format(round(255.87908765444,2), 'N2');
use string function substring & char index
select SUBSTRING(convert(varchar(20),round(255.87908765444,2)),
1,
CHARINDEX('.',convert(varchar(20),255.87908765444))+2)
select round(convert(decimal(18,2),255.87908765444),2)
Yes We can use the above solution is..
ROUND(CAST(psd.Price AS DECIMAL(20,4)), 2)