Newbie T-Sql Question

  • Can someone direct me to some help on where to find out how to pass the results of one query to another?

    Scenario is...

    I have a Product table, and a PriceListProductJoin Table. I need to be able to feed the Product Table a businesscodeid, and description and have the results (productID) sent to another query doing a select.

    These two do most of it:

    SELECT [ProductID]

    ,[BusinessCodeID]

    ,[InternetAvailable]

    ,[Discontinued]

    ,[DropShip]

    ,[ItemNumber]

    ,[Description]

    ,[DefaultPrice]

    FROM [Inventory].[dbo].[Product] where [BusinessCodeID] = '16' and Description like 'Paw%' (returns 6 rows)

    select * from [Inventory].[dbo].[PriceListProductJoin] where [PriceListID] = '2' and productid >= '2296' and productid <= '2300' (returns 6 rows)

    I know this is probably old hat for you all but it is making my head hurt.

    Thanks in Advance

  • Look up the INNER JOIN syntax in books online 😉

    Si

  • You can use Output Parameters on stored procedures. Those will return a value to the proc that calls a proc.

    They look like this:

    create proc dbo.MyProc (

    @OutputParam int output)

    as

    select @OutputParam = 5;

    And you call them like this:

    declare @Value int

    exec dbo.MyProc @OutputParam = @Value output

    Of course, that's a really over-simplified example. You can name them anything that's valid for a variable name, you can have complex T-SQL to assign values to them, etc. The syntax is like the above.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • thanks you guys/gals rock. That is generally all I need is a pointer in the right direction.

    Thanks.

  • You're welcome.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply