Link to home
Start Free TrialLog in
Avatar of soozh
soozhFlag for Sweden

asked on

Some TSQL ....

Hello,

My appologies if i have double posted this question but i have yet to fully understand the "new experts exchange".

I have a select statement below that uses a table valued function "GetPersonInfo".

This function takes one parameter which is the patients personal number that can be found as m.pat_Personnummer or p.pat_Personnummer.


select
  m.msr_id as [Unikt ID],
  m.pat_id as [PatientID],
  convert( date, m.msr_date) as [Registeringsdatum],
  i.PO_CONGR as [Folkbokföring],
  'Vet ej' as [Vårdform],
  m.kli_kliniknr as [Enhetens ID],
  k.kli_Namn as [Enhetens namn],
  'Vet ej' as [Kommun],
  p.pat_Gender as [Kön],
  CASE WHEN ISDATE(SUBSTRING( m.pat_Personnummer, 1, 8 )) = 1 THEN
    floor( datediff( day, convert( datetime, SUBSTRING( m.pat_Personnummer, 1, 8 )), m.msr_date) / 365.25)
  ELSE NULL END  as [Ålder]
from  dbo.Measurements m
  INNER JOIN dbo.Kliniker k ON m.kli_Kliniknr = k.kli_KlinikNr
  INNER JOIN dbo.Patients p ON m.pat_id = p.pat_id,
  dbo.getPersonInfo( p.pat_Personnummer ) i


However no matter what syntax i try i always get:
Msg 4104, Level 16, State 1, Line 17
The multi-part identifier "p.pat_Personnummer" could not be bound.

How should i write this statement?
ASKER CERTIFIED SOLUTION
Avatar of Anuj
Anuj
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
so, I basically agree with anujnb