473,503 Members | 5,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to "Include" another T-SQL Script

NeoPa
32,557 Recognized Expert Moderator MVP
I am looking to piece together a few T-SQL scripts into a single script in a way similar to the c "include BlahBlah.H" feature.

I've searched Online books and Googled but everything comes up with solutions that invoke an external script via OSQL or ISQL rather than a continuation of inline code (which is what I'm after).

It may well be that the reason is that this is not a supported feature. If so, please let me know. My experience level is that I get to play in here once every two or three years, so I get quite rusty.

If there is a more helpful answer that's fine too of course, but I'd like the view of someone with the current experience :)
Dec 10 '08 #1
12 18037
NeoPa
32,557 Recognized Expert Moderator MVP
I found http://bytes.com/groups/ms-sql/83051...call-sql-files in the archives. I suspect this means there is no support for this idea in T-SQL.

If anyone knows anything to the contrary then please post. Otherwise, I suspect this question can be considered to be answered.
Dec 10 '08 #2
Plater
7,872 Recognized Expert Expert
Could you save them as stored procedures and call them that way?
Dec 10 '08 #3
NeoPa
32,557 Recognized Expert Moderator MVP
I suppose if I got my thinking around how SQL Server generally works, that would be the best solution. I'm coming at it from a sort of different mind-set (file system based) because I'm not in SQL Server mode at the moment.

I think that is actually the logical solution. Thanks Plater :)
Dec 11 '08 #4
ck9663
2,878 Recognized Expert Specialist
That's actually the answer to your question. In C, the compiled program will not be able to see other module that are not included during compilation. Unless it's another executable that you want to call.

In SQL Server, once the function or stored proc is created, and you have the necessary rights, you can use it. If there are multiple copies of these modules in separate database or even within the database but of different owner, qualifying the call will allow you to use it.

-- CK
Dec 12 '08 #5
Plater
7,872 Recognized Expert Expert
I *am* curious how you would actually use a set of results returned from a stored procedure.
I cannot seem to find a way to use a SELECT statement on it, so unless it returns a scaler, how can it be used?
Dec 15 '08 #6
ck9663
2,878 Recognized Expert Specialist
Depending on what value want returned. You can either use a ReturnCode technique or use a Return Parameter (aka pass by reference) or use a Function instead of stored proc.

Happy Coding.


-- CK
Dec 15 '08 #7
Plater
7,872 Recognized Expert Expert
So there is no way to use a SELECT statement on a stored procedure results (it makes sense I guess since you never know what will be returned, one result set, two sets, etc etc)?
Dec 15 '08 #8
ck9663
2,878 Recognized Expert Specialist
Could you give an example of what you're trying to do?

-- CK
Dec 16 '08 #9
Plater
7,872 Recognized Expert Expert
Well for instance in a number of queries i have a sub query like:
SomeColumn in (SELECT SomeSimilarColumn FROM SomeTable WHERE (conditions) )

And it would be nice to have that elsewhere so if I make changes to it, everything that uses it is all set.

That sounds like a function I guess except that the subquery has been known to take parameters from its encompassing stored procedure.
Such as
Expand|Select|Wrap|Line Numbers
  1.  
  2. WHERE
  3. (
  4.    @myParam = 1 AND (conditions)
  5. OR
  6.    (some other conditions)
  7. )
  8.  
Dec 16 '08 #10
NeoPa
32,557 Recognized Expert Moderator MVP
I'm not at work today so I can't check this very easily (and I'm rusty as I mentioned), but I think a Stored Procedure is some code which doesn't return a value at all. Like a subroutine, but not a function.

If returned values are required, then a User Defined Function is required and that can return SELECTed results as a cursor if necessary. Otherwise it can return scalar values in more ordinary formats (int; bigint; nvarchar; etc; etc).

Please correct me if I'm wrong. I certainly could be, but that's my understanding.
Dec 16 '08 #11
ck9663
2,878 Recognized Expert Specialist
A function can return a value like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. if MyFunction(@myparameter) = Value
  3.  
  4.  
or multiple values that could act like a table like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. select column1, column2, column3 from MyFunction(@myparameter)
  3.  
  4.  
If you need the value of these columns as returned like a table, you can either use a cursor or some other technique to process each row and column.

As always, your function could be a single or a group of t-sql statements and, yes, you change it once and everything that uses it gets affected.

Hope I make sense :)

-- CK
Dec 16 '08 #12
Plater
7,872 Recognized Expert Expert
Hmmm.
I have quite a few stored procedures that do this:
Expand|Select|Wrap|Line Numbers
  1. WHERE
  2. (--
  3.     (
  4.         @IDNumber in 
  5.         (
  6.             SELECT WO.OwnerID 
  7.             FROM WebOwnership as WO
  8.             WHERE WO.IDType='PowerUser'
  9.         )
  10.         OR
  11.             T.Zone in
  12.             (--Only the correct zone(s)?
  13.                 SELECT O.IDString 
  14.                 FROM WebOwnership as O
  15.                 WHERE 
  16.                     O.OwnerID=@IDNumber
  17.                 AND
  18.                     O.IDType='ClientZone'
  19.             )
  20.     )
  21. AND
  22.     T.ClientID in
  23.     (--Only the correct Company(-ies)
  24.         SELECT O.IDNumber 
  25.         FROM WebOwnership as O
  26.         WHERE 
  27.             O.OwnerID=@IDNumber
  28.         AND
  29.             O.IDType='Client'
  30.         AND
  31.             O.OwnerType='Manager'
  32.     )
  33. )
  34.  

it would be nice to say like:
Expand|Select|Wrap|Line Numbers
  1. (
  2. @IDNumber in SomeFunc1()
  3. OR
  4. T.Zone in SomeFunc2(@IDNumber)
  5. )
  6. AND
  7. T.ClientID in SomeFunc3(@IDNumber)
  8.  
I will have to look into this
Dec 16 '08 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

5
6078
by: Danny Anderson | last post by:
Hola! I am working on a program where I am including a library that came with my numerical methods textbook. The "util.h" simply includes a large number of files. I had to change the util.h...
4
2844
by: michaaal | last post by:
I have two folders in my website... Folder1 (this is where my #include file is, this is where the style.css is) --Folder2 (Folder2 is inside of Folder1) Folder2 contains a file that has...
7
3532
by: mescaline | last post by:
Hi, Suppose a_file.cpp contains a function a_function() Now to include it in main_file.cpp I just do #include "a_file.cpp" and I'm all set. i recently came across this seemingly roundabout...
6
4303
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
4
15029
by: Exits Funnel | last post by:
Hello, I'm slightly confused about when to use parens around #included files and when to use angle brackets. I understand (I think) that the difference is that the compiler will search in its...
18
2610
by: Tuckers | last post by:
My question is, if I have created my own library which lives in its own install directory, to refer to its header file is it better to use #include "MyLibrary.h" or #include <MyLibrary.h> ...
2
2280
by: clusardi2k | last post by:
Hello, I'm trying to understand someone else code. The below compiles and works fine and dandy. #include <sys/types.h> #include "unistd.h" #include "stdio.h"
4
2272
by: bibsoconner | last post by:
Hi, I hope someone can please help me. I'm having a lot of trouble with schema files in .NET. I have produced a very simple example that uses "include" to include other schema files. It all...
2
2982
by: Susan Baker | last post by:
Hi, I am (trying) to compile some code I downloaded from the internet. The sources contain references to header files - using the form : #include <pathname/file> If I change the form to...
3
5136
by: Kceiw | last post by:
Dear all, When I use #include "queue.h", I can't link it. The error message follows: Linking... G:\Projects\Datastructure\Queue\Debug\main.o(.text+0x136): In function `main':...
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.