Did anybody hear if it's possible to define something like a
method/function/macrodefinition inside T-SQL? Particularly I have a few
SELECTs inside one T-SQL script and in most of them the WHERE CLAUSE is
absolutely same, but the retrieving results should be different and
according to these results the data flow should be different, so I can't
merge all these queries into one because the logic depends on the previous
results. The idea was to define this WHERE (...) as something to use it in
all queries inside this T-SQL. But I'm afraid that the standard T-SQL
doesn't allow us to do that because there are column names in this WHERE
clause. Temporary table? It will be huge and makes no sense.
Just D.Results from one table depending on results from another table sounds like a
join or union to me. Can you provide a more concrete example, e.g. table
structure, sample data, desired results?
"Just D." <no@.spam.please> wrote in message
news:nR6af.65318$WR2.43229@.fed1read03...
> Did anybody hear if it's possible to define something like a
> method/function/macrodefinition inside T-SQL? Particularly I have a few
> SELECTs inside one T-SQL script and in most of them the WHERE CLAUSE is
> absolutely same, but the retrieving results should be different and
> according to these results the data flow should be different, so I can't
> merge all these queries into one because the logic depends on the previous
> results. The idea was to define this WHERE (...) as something to use it in
> all queries inside this T-SQL. But I'm afraid that the standard T-SQL
> doesn't allow us to do that because there are column names in this WHERE
> clause. Temporary table? It will be huge and makes no sense.
> Just D.
>|||You could wrap your SQL inside a stored procedure, or even a user-defined
function. It's possible to parameterize either to make them flexible, and a
n
sp or udf is roughly equivalent to a method.
It's even possible to schedule a SQL script as a job; your DBA will be able
to help you with that.
Tell us a bit more about what you want to do and we'll try and help.
Damien
"Aaron Bertrand [SQL Server MVP]" wrote:
> Results from one table depending on results from another table sounds like
a
> join or union to me. Can you provide a more concrete example, e.g. table
> structure, sample data, desired results?
>
> "Just D." <no@.spam.please> wrote in message
> news:nR6af.65318$WR2.43229@.fed1read03...
>
>
Friday, March 9, 2012
Method/Definition inside T-SQL
Labels:
amethod,
database,
define,
definition,
fewselects,
function,
hear,
inside,
macrodefinition,
method,
microsoft,
mysql,
oracle,
particularly,
server,
sql,
t-sql
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment