Multi Column Set Null Value [closed] - sql

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 the following SQL Statement, which gives me an error.
UPDATE GNGRB.BS_CLOSING
SET ENDINGDATE + STATUS + STATUSDATE = NULL
WHERE UNIT = '231296' AND BMON = '2020114';
What is wrong with that code?

You can update multiple columns like that:
UPDATE GNGRB.BS_CLOSING
SET ENDINGDATE = NULL
,STATUS = NULL
,STATUSDATE = NULL
WHERE UNIT = '231296'
AND BMON = '2020114';

Related

How to classify a set of rows in SQL? [closed]

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 months ago.
Improve this question
I am trying to solve this SQL exercise. But I do not have any idea how to do it. Do someone have a good idea?
Try it out: https://dbfiddle.uk/fQmZkOaw
Something like:
SELECT workflow
, case when min(status) = max(status) THEN min(status) -- if all status is same, set to status
when min(case when status = 'Error' then 0 end) = 0 then 'Intederminate' -- if any status is error then intedermined
else 'Running' end
FROM #ProcessLog
group by workflow
mayhaps?

Get array values from json column [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 4 months ago.
Improve this question
I have a table in SQL Server, which has a column, which stores json object.
For example:
{
"definition":{
"analysisDefinitionId":16136,
"ptfProcLinkId":34959,
"version":2,
"dataVersion":1655821735508,
"originType":"uw",
"originPeriodFrequency":"an",
"developmentPeriodFrequency":"qu",
"startPeriod":"201001",
"endPeriod":"202109",
"calendarEnd":"202109",
"largeLosses":{
"excludeLargeLosses":[
],
"excludeLargeLossesEvents":[
"300063",
"302292"
]
},
"statisticalAdjustments":[
],
"includeCurrentPeriod":false,
"distributionMethod":"BF"
},
"includeCedentShift":true,
"calculateCedentShift":true,
"reportedClaimsType":"excluding_acr",
"userId":"195b47d7-6b8f-4ccd-a35b-eed688c5abc7",
"unit":"ones"
}
I want to retrieve values in this path: $.definition.largeLosses.excludeLargeLossesEvents, so basically to get two values: 300063, 302292, in two rows.
to recreate this scenario, you can run this:
CREATE TABLE [dbo].[bu_json_test]
( [id] INT IDENTITY (1, 1) NOT NULL,
[js_state] NVARCHAR (MAX) NULL
);
insert into [dbo].[bu_json_test] (js_state)
values ('{"definition":{"analysisDefinitionId":16136,"ptfProcLinkId":34959,"version":2,"dataVersion":1655821735508,"originType":"uw","originPeriodFrequency":"an","developmentPeriodFrequency":"qu","startPeriod":"201001","endPeriod":"202109","calendarEnd":"202109","largeLosses":{"excludeLargeLosses":[],"excludeLargeLossesEvents":["300063","302292"]},"statisticalAdjustments":[],"includeCurrentPeriod":false,"distributionMethod":"BF"},"includeCedentShift":true,"calculateCedentShift":true,"reportedClaimsType":"excluding_acr","userId":"195b47d7-6b8f-4ccd-a35b-eed688c5abc7","unit":"ones"}');
Now my select looks like this, but getting NULL values, altough select recognizes, that the result should have 2 rows:
SELECT
tbl.id,
gle.excludeLargeLossesEvents
FROM [dbo].[bu_json_test] tbl
OUTER APPLY OPENJSON(tbl.js_state, '$.definition.largeLosses.excludeLargeLossesEvents')
WITH (excludeLargeLossesEvents varchar(200)) gle
WHERE tbl.id = 1
So I expect
1 300063
1 302292
But getting
1 NULL
1 NULL

Missing right parenthesis SQL - * [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 6 years ago.
Improve this question
I am having trouble with this piece of code, as it is saying "Error at line 22
ORA-00907: missing right parenthesis" when I execute it.
SELECT DC.ACJ_ID,
DC.MCI_UNIQ_ID,
DG.GENDER_COMMON_DESC,
DR.RACE_COMMON_DESC,
AD.ADDRESS_LINE_1,
AD.ADDRESS_LINE_2,
AD.CITY,
AD.STATE,
AD.ZIP_CD,
AD.ZIP_CD_9,
DC_RANK
FROM DW_CLNTVIEW.FACT_CLIENT_WEEK_LATEST FCAS,
DW.DIM_GENDER DG,
DW.DIM_RACE DR,
DW.DIM_ADDRESS AD,
KLISA.JAIL_IDS DOC,
(SELECT ACJ_ID,
MCI_UNIQ_ID,
DENSE_RANK ()
OVER (PARTITION BY ACJ_ID
ORDER BY END_DATE DESC, EFF_DATE DESC, MCI_UNIQ_ID DESC ---REMOVE “MCI_UNIQ_ID DESC” TO ALLOW DUPLICATES ON ACJ_ID
DC_RANK
FROM DW.DIM_CLIENT) DC
WHERE FCAS.RACE_KEY = DR.RACE_KEY(+)
AND FCAS.SRC_SYS_KEY(+) = 0
AND FCAS.GENDER_KEY = DG.GENDER_KEY(+)
AND FCAS.ADDRESS_KEY = AD.ADDRESS_KEY(+)
AND DC.MCI_UNIQ_ID = FCAS.MCI_UNIQ_ID(+)
AND ACJS.ACJ_ID = DC.ACJ_ID(+)
AND DC_RANK(+) = 1;
You have unbalanced parenthesis.
(SELECT ACJ_ID,
Left.
OVER (PARTITION BY ACJ_ID
Another left.
FROM DW.DIM_CLIENT) DC
Closed one pair.
Thus leaving one open.

SQL: simple custom column in select doesn't work? [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 7 years ago.
Improve this question
If I add custom column in select, I get this error:
20018 Invalid column name '2'.
Here is query example
SELECT
[msg].[MessageTo],
[msg].[MessageFrom],
[msg].[SendTime],
[msg].[ReceiveTime],
[msg].[id],
'2' AS source,
[kat].[id] AS [CategoriId],
[kat].[naziv] AS [CategoriName]
FROM
[SMSServer_1].[dbo].[MessageIn] AS [msg]
LEFT JOIN [Tekijanka].[dbo].[crm_poruka] AS [por] ON [por].[fk_poruka] = [msg].[id]
AND [por].[fk_source] = [2]
LEFT JOIN [Tekijanka].[dbo].[crm_kategorije_poruka] AS [kat] ON [kat].[id] = [por].[fk_kategorija]
WHERE
msg.id NOT IN (
SELECT
fk_poruka
FROM
Tekijanka.dbo.crm_poruka
WHERE
fk_status <> 1
)
ORDER BY
[SendTime] DESC
Is there any way to fix it?
The problem is in LEFT JOIN, not in the SELECT section:
AND [por].[fk_source] = [2]
This condition tries to join fk_source and column named [2]. Of course, there's no such column in tables MessageIn and crm_poruka. You have to change this part of the code (remove the condition or change it to AND [por].[fk_source] = 2).

SQL Server update [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 8 years ago.
Improve this question
I'm trying to write an update query for SQL Server, for example:
UPDATE x
SET Col1 = y.Col1,
Col2 = y.Col2,
Col3 = y.Col3
FROM
Table1 AS x
INNER JOIN
Table2 AS y ON x.ID = y.ID
But I get an error
Error: near "FROM": syntax error"
I saw same syntax in similar answers, but I can't understand why I get the error
Thanx in advance.
Let's try this: I didn't test the code below so, please kindly let me know the result. Thanks
UPDATE x
SET x.Col1 = y.Col1,
x.Col2 = y.Col2,
x.Col3 = y.Col3
FROM
Table1 AS x
INNER JOIN
Table2 AS y ON x.ID = y.ID
Hope it helps.