Guest User

Untitled

a guest
Jul 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. CREATE PROCEDURE [dbo].[LIST_CLIENTS]
  2.  
  3. CREATE TABLE #CLIENT(
  4. --Varchar And Numeric Values goes here
  5. )
  6.  
  7. /*Several Select's and Insert's against the Temporary Table*/
  8.  
  9. SELECT * FROM #CLIENT
  10.  
  11. END
  12.  
  13. sp_configure 'Show Advanced Options', 1
  14. GO
  15. RECONFIGURE
  16. GO
  17.  
  18. sp_configure 'Ad Hoc Distributed Queries', 1
  19. GO
  20. RECONFIGURE
  21. GO
  22.  
  23. SELECT *
  24. INTO #CLIENT
  25. FROM OPENROWSET
  26. ('SQLOLEDB','Server=(local);Uid=Cnx;pwd=Cnx;database=r8;Trusted_Connection=yes;
  27. Integrated Security=SSPI',
  28. 'EXEC dbo.LIST_CLIENTS ''20110602'', NULL, NULL, NULL, NULL, NULL')
  29.  
  30. Msg 208, Level 16, State 1, Procedure LIST_CLIENTS, Line 43
  31. Invalid object name '#CLIENT'.
  32.  
  33. USE tempdb;
  34. GO
  35. CREATE PROCEDURE dbo.proc_x
  36. AS
  37. BEGIN
  38. SET NOCOUNT ON;
  39.  
  40. DECLARE @x TABLE(id INT);
  41. INSERT @x VALUES(1),(2);
  42. SELECT * FROM @x;
  43. END
  44. GO
  45.  
  46. SELECT *
  47. INTO #client
  48. FROM OPENQUERY
  49. (
  50. [loopback linked server name],
  51. 'EXEC tempdb.dbo.proc_x'
  52. ) AS y;
  53.  
  54. SELECT * FROM #client;
  55.  
  56. DROP TABLE #client;
  57.  
  58. DROP PROCEDURE dbo.proc_x;
  59.  
  60. IF OBJECT_ID('dbo.temptable', 'U') IS NOT NULL
  61. BEGIN
  62. DROP TABLE dbo.temptable
  63. END
  64.  
  65. CREATE TABLE dbo.temptable
  66. ( ... )
  67.  
  68. declare @t table(ID int, Name varchar(15));
  69. if (0 = 1) select ID, Name from @t; -- fake SELECT statement
  70. create table #T (ID int, Name varchar(15));
  71. select ID, Name from #T; -- real SELECT statement
  72.  
  73. declare @fmtonlyOn bit = 0;
  74. if 1 = 0 set @fmtonlyOn = 1;
  75. set fmtonly off;
  76. create table #T (ID int, Name varchar(15));
  77. if @fmtonlyOn = 1 set fmtonly on;
  78. select ID, Name from #T;
Add Comment
Please, Sign In to add comment