Domanda

I like to join to sets of data.

Not sure why the following is not working:

    (Select  LocID,  ParamID,  alertNumExceed, upperAlarm,  lowerAlarm,  alertOn,  EntryUserID,  ParamOrder 
     from data_LocParams )  dl 
     inner join 
    (SELECT LocId 
    from map_Sites ms
    inner join map_WaterSystems mw on mw.SiteId = ms.SiteId
    inner join map_Locations ml on mw.SysID = ml.SysID
    where ms.SiteId = 344 )  mq
    on dl.LocID = mq.LocId   

I get the following error:

Msg 102, Level 15, State 1, Line 3 Incorrect syntax near 'dl'. Msg 102, Level 15, State 1, Line 9 Incorrect syntax near 'mq'.

È stato utile?

Soluzione

You haven't selected anything

SELECT dl.LocID,  ParamID,  alertNumExceed, upperAlarm,  lowerAlarm,  alertOn,  EntryUserID,  ParamOrder  
FROM
    (Select  LocID,  ParamID,  alertNumExceed, upperAlarm,  lowerAlarm,  alertOn,  EntryUserID,  ParamOrder 
     From data_LocParams )  dl 
     inner join 
    (SELECT LocId 
    from map_Sites ms
    inner join map_WaterSystems mw on mw.SiteId = ms.SiteId
    inner join map_Locations ml on mw.SysID = ml.SysID
    where ms.SiteId = 344 )  mq
    on dl.LocID = mq.LocId

Altri suggerimenti

Assume that map_Locations has column named LocId, query can be simplified to

Select  dl.LocID,  dl.ParamID,  dl.alertNumExceed, dl.upperAlarm,  dl.lowerAlarm,  dl.alertOn,  dl.EntryUserID,  dl.ParamOrder 
from data_LocParams dl 
inner join map_Locations ml on dl.LocId = ml.DocId
inner join map_WaterSystems mw on mw.SysID = ml.SysID
inner join map_Sites ms on mw.SiteId = ms.SiteId
WHERE ms.SiteId = 344

or

Select  dl.LocID,  dl.ParamID,  dl.alertNumExceed, dl.upperAlarm,  dl.lowerAlarm,  dl.alertOn,  dl.EntryUserID,  dl.ParamOrder 
from map_Sites ms
inner join map_WaterSystems mw on mw.SiteId = ms.SiteId
inner join map_Locations ml on mw.SysID = ml.SysID
inner join from data_LocParams on dl.LocID = mq.LocId   
on dl.LocID = mq.LocId  
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top