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 |
|
hasanali00
Posting Yak Master
207 Posts |
Posted - 2006-02-10 : 08:23:42
|
| I seem to have a problem referenceing my temporary table:CREATE PROCEDURE SearchAttributesAsDECLARE @NewTable TABLE (productid nvarchar(50), valueforType1 int, valueForType2 int) INSERT INTO @NewTable (productid)SELECT p.productID FROM ProductAttributeValues p UPDATE @NewTable SET ValueForType1 = (Select pat.attributeValueID FROM ProductAttributeValues pat INNER JOINAttributeValues av on pat.AttributeValueID = av.AttributeValueID where av.attributeTypeID = 1 )where exists(select pat1.ProductID from ProductAttributeValues where pat1.productid = @NewTable.ProductID)GoI get the error: Must declare the variable @NewTableAny ideas please?? Thanks |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-02-10 : 08:28:12
|
| >> (select pat1.ProductID from ProductAttributeValues where pat1.productid = @NewTable.ProductID)(select x.ProductID from ProductAttributeValues x inner join @NewTable y on x.ProductID = y.ProductID)----------------------------------'KH'everything that has a beginning has an end |
 |
|
|
jimmy_a
Starting Member
38 Posts |
Posted - 2006-02-10 : 08:33:10
|
| (select pat1.ProductID from ProductAttributeValues A, @NewTable B where A.productid = B.ProductID) |
 |
|
|
hasanali00
Posting Yak Master
207 Posts |
Posted - 2006-02-10 : 09:21:12
|
| Thanks for the replies. I have resolved the problem, but now when I run this SP, I get this error:"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.The statement has been terminated."My SP is :CREATE PROCEDURE SearchAttributesTableAsDECLARE @NewTable TABLE (productid nvarchar(50), valueforType1 int, valueForType2 int) INSERT INTO @NewTable (productid) SELECT distinct p.productID FROM ProductAttributeValues pUPDATE @NewTable SET ValueForType1 = (Select pat.attributeValueID FROM ProductAttributeValues pat INNER JOINAttributeValues av on pat.AttributeValueID = av.AttributeValueID where av.attributeTypeID = 3)where exists (select tb.productid from @NewTable tb, ProductAttributeValues pat1 where tb.productid = pat1.productid)SELECT * FROM @NewTableGOBasically, @NewTable holds 4 rows. For each row, I want to update the AttributeValueID where the @NewTable.ProductID is same as ProductAttributes.ProductIDWhat could I be doing wrong. Regards |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-02-10 : 09:23:59
|
| The General approach is Update T1set col=T2.colfrom table1 T1 inner join table2 T2on T1.keycol=T2.keycolMadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-02-10 : 09:25:51
|
Try this :UPDATE nt SET nt.ValueForType1 = pa.attributeValueIDFROM @NewTable nt INNER JOIN ProductAttributeValues pa ON nt.productid = pa.productid INNER JOIN AttributeValues av ON pa.AttributeValueID = av.AttributeValueIDWHERE av.attributeTypeID = 3 ----------------------------------'KH'everything that has a beginning has an end |
 |
|
|
hasanali00
Posting Yak Master
207 Posts |
Posted - 2006-02-10 : 09:34:36
|
| Thank guys. I spent a lot of time on this SP :) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-02-10 : 09:37:40
|
>> I spent a lot of time on this SP :)But Tan made you to leave rest of the time MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|