Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ITSSQL
Starting Member
8 Posts |
Posted - 2006-07-14 : 10:50:50
|
| Hello I have two tables table1 has two columns as "product_id(PK)" and "product_type"table2 has three columns as "ID (PK)", product_type and "template_code"I have written a stored procedure to return template_code based on product_idwhat I want to do is, 1. read product_type from table1 using product_id 2. read template_code from table2 using product_typemy stored procedure Create PROCEDURE [dbo].[MyTest10Procedure] @product_id int,@template_code nvarchar(50) outputASBEGINSET NOCOUNT ON;Declare @product_type int ;Select product_typefrom dbo.table1where product_id=@product_idSelect template_codefrom dbo.table2where product_type=@product_typeENDwhen i execute this store procedure I get data from only table1 but no data from table2.Can anyone suggests whats wrong here?Thanks |
|
|
humanpuck
Yak Posting Veteran
94 Posts |
Posted - 2006-07-14 : 11:02:07
|
| Try thisSelect Product_Type, Template_Codefrom dbo.table1 a inner join dbo.table2 bon a.product_type = b.product_typewhere a.product_id = @product_idand b.product_type=@product_type |
 |
|
|
datagod
Starting Member
37 Posts |
Posted - 2006-07-14 : 11:02:24
|
| Try executing this stored procedure from within Query Analyzer. You should see two result sets.Some clients will only capture the first result set and ignore all others.If you are still getting problems, make sure you did not accidentally create an older version of the proc in Master.Hope it helps... |
 |
|
|
ITSSQL
Starting Member
8 Posts |
Posted - 2006-07-14 : 11:15:46
|
| Thanks, Humanpuck, I do not have product_id column in table2, so I can not use inner join htere. |
 |
|
|
humanpuck
Yak Posting Veteran
94 Posts |
Posted - 2006-07-14 : 11:24:38
|
quote: Originally posted by ITSSQL Thanks, Humanpuck, I do not have product_id column in table2, so I can not use inner join htere.
Join em up on product type. I changed the query above. |
 |
|
|
ITSSQL
Starting Member
8 Posts |
Posted - 2006-07-14 : 18:30:41
|
| Thanks a lot. |
 |
|
|
|
|
|