Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.41 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. getting multiple values from one table and using to retrive data from other table in stored procedure in sql server [closed]
  2. cart table
  3.     CartId,
  4.     PrdouctId -> should retrieve data from productinfo table
  5.     EmailId ->should Retrieve data from cart table that who many cart are register in this EmailId
  6.     cost,
  7.     Quantity ,
  8.     Ram -> contains HardWareId
  9.     GraphicCard ->contains HardWareId
  10.     ScreenSize ->contains HardWareId
  11.  
  12. ProductInfo Table
  13.     ProductId,
  14.     BrandlName,
  15.     ModelName,
  16.     Processor,
  17.  
  18. HardwareInfo table
  19.     HardWareId,
  20.     HardwareName,
  21.     HarwareCost,
  22.        
  23. Select @ProductId =[productId],@Ram = [Ram] from cart where EmailId = @EmailId
  24. Select [BrandName],[ModelName] from ProductInfo where ProductId = @productId
  25. select [HardwareName],[HardwareCost] from HardwareInfo where HardwareId = @Ram
  26.        
  27. create procedure GetCartByEmailId
  28.   @EmailId int
  29. as  
  30.  
  31. select P.BrandName,
  32.        P.ModelName,
  33.        HR.HardwareName as RamName,
  34.        HR.HardwareCost as RamCost,
  35.        HG.HardwareName as GraphicCard,
  36.        HG.HardwareCost as GraphicCardCost,
  37.        HS.HardwareName as ScreenSize
  38. from Cart as C
  39.   inner join ProductInfo as P
  40.     on C.ProductId = P.ProductId
  41.   left outer join HardwareInfo as HR
  42.     on C.Ram = HR.HardwareID
  43.   left outer join HardwareInfo as HG
  44.     on C.GraphicCard = HG.HardwareID
  45.   left outer join HardwareInfo as HS
  46.     on C.ScreenSize = HS.HardwareID
  47. where C.EmailId = @EmailId