1
votes

I want to do a select using the stored procedure. My code:

ALTER PROCEDURE [dbo].[PUser]
@nom VARCHAR(50) = '',
@prenom VARCHAR(50) = '',
@model VARCHAR(50) = '',
@immatriculation VARCHAR(50) = '',
@marque VARCHAR(50) = '',
@AntenneId int = NULL,
@ProfilId int = NULL,
@puissance int = NULL
AS
BEGIN
    SELECT  usr.USERID,usr.LOGIN,usr.NAME,usr.SURNAME,usr.DTECRE,usr.DTEUPD,usr.DTEEXP,
            usr.DEFAULTURL,usr.Tel,usr.Celular,usr.Email,usr.AntenneId,pf.ProfilId,pf.ProfilLib,ant.Libelle,
            car.MarqueVoiture,car.ModelVoiture,car.Puissance,car.Immatriculation
    FROM [TCN_USERS] usr,[TUserVoiture] car
     inner join dbo.TAdmProfilUser pfu ON pfu.UserId = usr.USERID
     inner join dbo.TAdmProfil pf ON pf.ProfilId = pfu.ProfilId
     left join dbo.TParamAntennes ant ON usr.AntenneId = ant.AntenneId
    WHERE
    usr.NAME like '%' + @nom + '%' AND
    usr.SURNAME like '%' + @prenom + '%' AND
    car.ModelVoiture like '%' + @model + '%' AND
    car.Immatriculation like '%' + @immatriculation + '%' AND
    car.ModelVoiture like '%' + @model + '%' AND
    car.MarqueVoiture like '%' + @marque + '%' AND
    car.Puissance = @puissance AND
    usr.AntenneId = @AntenneId AND
    pf.ProfilId = @ProfilId
END

When I execute that code in sql server I get this error:

Msg 4104, Level 16, State 1, Procedure PUser, Line 13

The multi-part identifier "usr.USERID" could not be bound.

Msg 4104, Level 16, State 1, Procedure PUser, Line 13

The multi-part identifier "usr.AntenneId" could not be bound.

Please any person can help me to solve my problem. Thank you!

1

1 Answers

2
votes

The issue is here:

FROM [TCN_USERS] usr,[TUserVoiture] car
inner join dbo.TAdmProfilUser pfu ON pfu.UserId = usr.USERID

You are trying to mix the JOINS(explicit and implicit JOINS). Explicit JOINS have a precedence over the implicit JOINS.

You can try it like this:

FROM ([TCN_USERS] usr,[TUserVoiture] car)

As a word of caution: Try to avoid mixing of JOINS(explicit and implicit JOINS) as it is confusing for you as well as for others who will work on it.

A good advice is to use explicit JOINS only.