7
votes
Variable SQL join operator using case statement
CASE is not a statement, it returns a value expression, so it's not going to work in a situation where you need a logic boolean result. You can just use OR instead
SELECT *
FROM SickLeave lv
INNER ...
4
votes
Deleting multiples that aren't exact PostgreSQL
From the description it seems that you are trying to fix the data. In your case id should be PRIMARY KEY, and the year column UNIQUE.
If you just want to select the data use,
WITH distinctYears AS (
...
4
votes
Guarantee SQL Management Studio Query
Sounds to me like you (and Change Management) are concerned about people running SQL directly in your [Production] databases and making changes to the wrong database.
Management Studio cannot directly ...
2
votes
Guarantee SQL Management Studio Query
It's a little unclear what you're asking but let me do my best to address each of your questions:
When running a query in SQL Server Management Studio, is it then possible to guarantee that the ...
2
votes
Deleting multiples that aren't exact PostgreSQL
It's not clear what the actual rule should be, but if is that year must be id+1999 then:
DELETE FROM tablename WHERE year <> id+1999
would be more than enough (but then one wonders why you have ...
1
vote
Accepted
Variable SQL join operator using case statement
Case returns a value expression, but that does not mean that it cannot be used in this case. Just need to have it return a value than is then used in a comparison, as this:
SELECT
*
FROM SickLeave ...
1
vote
Accepted
Sql Server: Query to parse and validate codes
One relational way you can do this is by splitting your #SourceData first (fortunately you have access to the STRING_SPLIT() function despite being on an outdated version of SQL Server), then getting ...
1
vote
Sql Server: Query to parse and validate codes
-- first thing that comes to mind:
SELECT
sd.ID
, sd.Codes
, CASE
WHEN NOT EXISTS (
SELECT x.[value]
FROM string_split(sd.Codes, ';') as x
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
query × 1590mysql × 441
sql-server × 410
postgresql × 299
join × 133
query-performance × 113
performance × 99
oracle × 97
subquery × 76
t-sql × 71
select × 66
mariadb × 58
optimization × 58
group-by × 44
syntax × 43
database-design × 39
sql-server-2008 × 37
ms-access × 34
plsql × 33
count × 31
oracle-11g-r2 × 30
update × 29
sql-server-2016 × 28
index × 27
aggregate × 25