Note that there are some explanatory texts on larger screens.

plurals
  1. POthe select query based on inner join doesn´t work, returns nothing
    primarykey
    data
    text
    <p>I have the code below that does not return any values when it should. Is there anyone that can find anything faulty with it? When I run the script I get 0 values in return (0 rows affected), even though I know that there are rows that should be selected.</p> <p>This is just a part of the whole script, and when I run everything I get the error message "Warning: Null value is eliminated by an aggregate or other SET operation". But I don´t know what this implies for my script. I only have 1 "group by" in the script (which I don´t post here since that coding works). Does anyone know?</p> <p>The code, below, should create a temp-table and to the temp-table insert rows from the table "StatusHistorik" where the following conditions are met: </p> <p>1) [NyStatus]=4 (NyStatus is a column from the table "StatusHistorik"), </p> <p>2) The variable "EnhetsId" should not exist in the table "SKL_AdminKontroll_SkaÅtgärdas" (F). Code: "F.EnhetsId is null". </p> <p>I have used inner joins in both cases. This should result in a number of observations/rows in the temp-table, but returns nothing. Does anyone find any errors with the coding that could explain the absent of result?</p> <p>I should mention that when I "comment away" the last inner join and the last part of the where-statement, the script works as it is supposed to. So I suspect that it is the last inner join-statement that is wrong somehow. </p> <pre><code>declare @temp2 table ( EnhetsId varchar(50), TjanstId Int, Tabell varchar(50), Kommentar ntext, Uppdaterad datetime ); WITH ENHET_AVSLUT AS ( SELECT DISTINCT A.[EnhetsId] FROM [StatistikinlamningDataSKL].[dbo].[StatusHistorik] A inner join ( select [EnhetsId], max(SenastUppdaterad) as SenastDatum from [StatistikinlamningDataSKL].[dbo].[StatusHistorik] group by [EnhetsId] ) B on A.[EnhetsId] = B.[EnhetsId] and A.[SenastUppdaterad] = B.SenastDatum INNER JOIN StatistikinlamningDataSKL.dbo.SKL_AdminKontroll_SkaÅtgärdas F ON A.EnhetsId = F.EnhetsId WHERE [NyStatus] = 4 AND F.EnhetsId is null ) insert into @temp2 (EnhetsId, TjanstId, Tabell, Kommentar, Uppdaterad) SELECT EnhetsId, 1, ''GR_PS09_1'', ''OK'', getdate() from ENHET_AVSLUT select * from @temp2 </code></pre> <p>Best regards, Hannes</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload