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

Untitled

By: a guest on May 27th, 2012  |  syntax: None  |  size: 2.23 KB  |  hits: 23  |  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. -- ================================================
  2. -- Template generated from Template Explorer using:
  3. -- Create Procedure (New Menu).SQL
  4. --
  5. -- Use the Specify Values for Template Parameters
  6. -- command (Ctrl-Shift-M) to fill in the parameter
  7. -- values below.
  8. --
  9. -- This block of comments will not be included in
  10. -- the definition of the procedure.
  11. -- ================================================
  12. SET ANSI_NULLS ON
  13. GO
  14. SET QUOTED_IDENTIFIER ON
  15. GO
  16. -- =============================================
  17. -- Author:              <Author,,Name>
  18. -- Create date: <Create Date,,>
  19. -- Description: <Description,,>
  20. -- =============================================
  21. ALTER PROCEDURE updateQuestions
  22.         -- Add the parameters for the stored procedure here
  23. AS
  24. BEGIN
  25.         -- SET NOCOUNT ON added to prevent extra result sets from
  26.         -- interfering with SELECT statements.
  27.         SET NOCOUNT ON;
  28.  
  29.     -- Insert statements for procedure here
  30.  
  31.          CREATE TABLE #Results
  32.     (
  33.                 version INT,
  34.                 field_length INT,
  35.         field_type_id INT,
  36.         html_form_type_id INT,
  37.         is_required tinyint,
  38.         name varchar(255),
  39.         precision INT,
  40.         question_type_id INT,
  41.         has_comments tinyint,
  42.         hasna tinyint,
  43.         sort_order INT
  44.     )
  45.     DECLARE @sqlQuery nvarchar(max);
  46.     SET @sqlQuery =
  47.                                         'Select version, field_length, field_type_id, html_form_type_id, is_required, name, precision,
  48.                                          CASE question_type_id
  49.                                                 WHEN 1 THEN 28
  50.                                                 WHEN 2 THEN 29
  51.                                                 WHEN 3 THEN 30
  52.                                                 WHEN 4 THEN 32
  53.                                                 WHEN 5 THEN 33
  54.                                                 WHEN 6 THEN 34
  55.                                                 WHEN 7 THEN 35
  56.                                                 WHEN 8 THEN 36
  57.                                                 WHEN 13 THEN 37
  58.                                         END as question_type_id, has_comments, hasna, sort_order
  59.                                         FROM question
  60.                                         WHERE question_type_id in (1,2,3,4,5,6,7,8,13)'
  61.                                        
  62.         PRINT @sqlQuery
  63.    
  64.     INSERT #Results
  65.                 EXEC(@sqlQuery);
  66.                
  67.         --set identity_insert mbit.dbo.question on;
  68.         SET @sqlQuery = 'INSERT INTO [MBIT].[dbo].[question]
  69.         (
  70.                 version, field_length, field_type_id, html_form_type_id, is_required, name, precision,
  71.                                         question_type_id, has_comments, hasna, sort_order
  72.         )
  73.         Select *
  74.                                         FROM #Results'
  75.        
  76.         EXEC(@sqlQuery)
  77.         --set identity_insert mbit.dbo.question off;   
  78. SELECT * FROM #Results;
  79.         DROP TABLE #Results;
  80.         RETURN
  81.        
  82. END
  83.  
  84. GO