今天写的一个存储过程

  1. begin
  2. createtable#table
  3. (
  4. theIDintidentity(1,1),
  5. PriceNamevarchar(1000),
  6. theDatedatetime,
  7. Pricesvarchar(1000),
  8. theCTIDsvarchar(500)
  9. )
  10. declare@MyDatedatetime
  11. DECLAREmycursorCURSORFOR--创建一个游标
  12. selectdistinctTicketDatefromConceTablewhereTicketID=5
  13. OPENmycursor
  14. FETCHNEXTFROMmycursor
  15. INTO@MyDate
  16. WHILE@@FETCH_STATUS=0
  17. BEGIN
  18. declare@Myid1int,@thePriceNamesvarchar(1000),@thePricesvarchar(5000),@theCTIDvarchar(2000)
  19. set@thePriceNames=''
  20. set@thePrices=''
  21. set@theCTID=''
  22. DECLAREmycursor1CURSORFOR--创建一个游标
  23. selectCTIDfromdbo.ConceTablewhereTicketDate=@MyDateorderbyCTID
  24. OPENmycursor1
  25. FETCHNEXTFROMmycursor1
  26. INTO@Myid1
  27. WHILE@@FETCH_STATUS=0
  28. BEGIN
  29. declare@theConcessionsvarchar(100),@thePricevarchar(1000)
  30. select@theConcessions=ConcessionsfromConceTablewhereCTID=@Myid1
  31. set@thePriceNames=@thePriceNames+'|'+@theConcessions
  32. --set@thePriceNames=@theConcessions
  33. select@thePrice=[TicketPrice]fromConceTablewhereCTID=@Myid1
  34. --set@thePrices=@thePrices+'|'+@thePrice
  35. set@theCTID=@theCTID+'|'+CONVERT(varchar(1000),@Myid1)
  36. set@thePrices=@thePrices+'|'+@thePrice
  37. --select@Myid1,@thePriceNames,@thePrices,@theConcessions,@thePrice
  38. FETCHNEXTFROMmycursor1
  39. INTO@Myid1
  40. END
  41. CLOSEmycursor1
  42. DEALLOCATEmycursor1
  43. insertinto#tablevalues(@thePriceNames,@MyDate,@thePrices,@theCTID)
  44. FETCHNEXTFROMmycursor
  45. INTO@MyDate
  46. END
  47. CLOSEmycursor
  48. DEALLOCATEmycursor
  49. select*from#table
  50. droptable#table
  51. end
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值