fwstealer
asked on
inner join
i've got an inner join that uses two separate sql servers and tables as linked servers. when i provide an id it works but when i try a variable it returns no data and im not sure why
DECLARE @MyFlightId varchar
SET @MyFlightId = '1242740'
select flights.flightid as 'Astro.Flights.FlightID', ExpenseReport.FlightID as 'Pronto.ExpenseReport.Flig htID',
ExpenseReport.ID,ExpenseRe port.Pront oID,Expens eReport.To daysDate,E xpenseRepo rt.PIC,Exp enseReport .SIC,
ExpenseReport.TailNo,Expen seReport.F lightLog,E xpenseRepo rt.NoRecei ptsAttache d,
ExpenseReport.NoFuelCards, ExpenseRep ort.DepICA O,ExpenseR eport.PAX, ExpenseRep ort.FBONam e,
ExpenseReport.FBOPaymentTy pe,Expense Report.Raf t,ExpenseR eport.Cate ring,
ExpenseReport.RetailFuelPr ice,Expens eReport.Ga llonsPurch ased,Expen seReport.G eoStamp,
ExpenseReport."1Fees",Expe nseReport. "1FeeAmoun t",Expense Report."2F ees",
ExpenseReport."2FeeAmount" ,ExpenseRe port."3Fee s",Expense Report."3F eeAmount",
ExpenseReport."4Fees",Expe nseReport. "4FeeAmoun t",Expense Report."5F ees",
ExpenseReport."5FeeAmount" ,ExpenseRe port."6Fee s",Expense Report."6F eeAmount"
from ExpenseReport with(nolock)
inner join astrosql2.astro.dbo.tm_fli ghts flights with(nolock) on ExpenseReport.FlightID = flights.flightid
where ExpenseReport.FlightID = @MyFlightId -- returns no row
--where ExpenseReport.FlightID = '1242740' -- returns my row
DECLARE @MyFlightId varchar
SET @MyFlightId = '1242740'
select flights.flightid as 'Astro.Flights.FlightID', ExpenseReport.FlightID as 'Pronto.ExpenseReport.Flig
ExpenseReport.ID,ExpenseRe
ExpenseReport.TailNo,Expen
ExpenseReport.NoFuelCards,
ExpenseReport.FBOPaymentTy
ExpenseReport.RetailFuelPr
ExpenseReport."1Fees",Expe
ExpenseReport."2FeeAmount"
ExpenseReport."4Fees",Expe
ExpenseReport."5FeeAmount"
from ExpenseReport with(nolock)
inner join astrosql2.astro.dbo.tm_fli
where ExpenseReport.FlightID = @MyFlightId -- returns no row
--where ExpenseReport.FlightID = '1242740' -- returns my row
Are you sure ExpenseReport.FlightID is a varchar, not an int or something?
Also, try removing those with (nolock) table hints, see what that does..
ASKER
i removed the no lock - returned nothing
yes one is a varchar.
--astro flights [FlightID] [dbo].[PrimaryKey] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
--pronto expense report [FlightID] [varchar](1000) NULL
yes one is a varchar.
--astro flights [FlightID] [dbo].[PrimaryKey] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
--pronto expense report [FlightID] [varchar](1000) NULL
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Perhaps you need
SET @MyFlightId = "'1242740'"
SET @MyFlightId = "'1242740'"
I think AngelIII has the solution - sizing the varchar to something sensible
ASKER
can't believe i didn't see that one - duh