troubleshooting Question

Some TSQL ....

Avatar of soozh
soozhFlag for Sweden asked on
Microsoft SQL Server 2008SQL
3 Comments2 Solutions312 ViewsLast Modified:

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.

  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?
SQL Server DBA
Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros