views:

40

answers:

1

i have used joins to get datas from two tables under comman name. as

SELECT userValidity.UserName, userValidity.ValidFrom,userValidity.ValidUpTo,userValidity.TotalPoints, persons.SenderID FROM userValidity INNER JOIN persons ON userValidity.Username=tbl_persons.Username

but i need to execute this query with oly the username which i pass as parameter in stored procedure..

how to pass the username in stored procedure in this joins.

alter procedure GetNameIDUserInformation ( @user varchar(max) ) as begin

SELECT userValidity.UserName, userValidity.ValidFrom,userValidity.ValidUpTo,userValidity.TotalPoints, persons.SenderID FROM userValidity INNER JOIN persons ON userValidity.Username=tbl_persons.Username end

in this SP, where i have to pass the user parameter to get the single row of my user record

A: 

What happens if you just add WHERE userValidity.Username=user to the query? :

alter procedure GetNameIDUserInformation ( @user varchar(max) ) as
begin
    SELECT userValidity.UserName,
    userValidity.ValidFrom,userValidity.ValidUpTo,
    userValidity.TotalPoints, persons.SenderID
    FROM userValidity
    INNER JOIN persons
    ON userValidity.Username=tbl_persons.Username end
    WHERE userValidity.Username=user

If you get a syntax error around user, consider using a different name, as user is a reserved keyword in some RDBMSes.

Joey Adams
ya thanks.. it works out fine.
Ranjana