Home All Groups Group Topic Archive Search About
Author
8 Sep 2006 3:57 PM
Mark Goldin
Can I create a function that can be a part of a SELECT statement and it
would be capable of accepting a parameter that is a column name from one of
the tables in the statement?

Thanks

Author
8 Sep 2006 4:18 PM
Hilary Cotter
I am not sure but how about a case statement

declare @columnNumber int
set @columnNumber=1
select name, type, id, xtype, dynamiccolumn =case
when @columnNumber=1 then convert(varchar(20),name)
when @columnNumber=2 then convert(varchar(20),type)
when @columnNumber=3 then convert(varchar(20),id)
when @columnNumber=4 then convert(varchar(20),xtype) end

from sysobjects

--
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.

This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.

Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html

Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com



Show quote
"Mark Goldin" <mgol***@ufandd.com> wrote in message
news:ewcLH%2310GHA.4796@TK2MSFTNGP03.phx.gbl...
> Can I create a function that can be a part of a SELECT statement and it
> would be capable of accepting a parameter that is a column name from one
> of the tables in the statement?
>
> Thanks
>
Author
8 Sep 2006 4:21 PM
David Browne
<DIV>&quot;Mark Goldin&quot; &lt;mgol***@ufandd.com&gt; wrote in message
news:ewcLH%2310GHA.4796@TK2MSFTNGP03.phx.gbl...</DIV>> Can I create a
function that can be a part of a SELECT statement and it
> would be capable of accepting a parameter that is a column name from one
> of the tables in the statement?
>

Yes, that's basically what functions are for.

Although if it is a Table-Valued function this only works on SQL 2005 using
the APPLY operators.

David
Author
8 Sep 2006 4:47 PM
Mark Goldin
Here is my statement

select runningjobs.id, runningjobs.job, nneedqty, description, rtrim(name) as name,

reason, seconds, amountnoscans, downtime, total_scan

from udf_GetJobs('09/08/2006', 5) a

inner join runningjobs

on a.job = runningjobs.job

left join jobclosingdetail

on runningjobs.id = jobclosingdetail.job_id

inner join jobstatus

on active = jobstatus.status

inner join categorymachines

on jobcategory = categorymachines.id

inner join runningmachine r

on r.runningjob_id = runningjobs.id

cross apply udf_GetTotalBeingMade(r.id) as totalmade

order by runningjobs.job

I am getting an error in cross apply udf_GetTotalBeingMade(r.id) as totalmade

Can you help, please?

Show quote
"David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in message news:%23yyEVL20GHA.1040@TK2MSFTNGP06.phx.gbl...
>
>
> <DIV>&quot;Mark Goldin&quot; &lt;mgol***@ufandd.com&gt; wrote in message
> news:ewcLH%2310GHA.4796@TK2MSFTNGP03.phx.gbl...</DIV>> Can I create a
> function that can be a part of a SELECT statement and it
>> would be capable of accepting a parameter that is a column name from one
>> of the tables in the statement?
>>
>
> Yes, that's basically what functions are for.
>
> Although if it is a Table-Valued function this only works on SQL 2005 using
> the APPLY operators.
>
> David
>
Author
8 Sep 2006 5:09 PM
David Browne
>"Mark Goldin" <mgol***@ufandd.com> wrote in message
>news:ew21tZ20GHA.4656@TK2MSFTNGP04.phx.gbl...
>Here is my statement
.. . .
>Can you help, please?


Please provide DDL and sample data.
http://www.aspfaq.com/etiquette.asp?id=5006



David
Author
8 Sep 2006 5:14 PM
Mark Goldin
Like I said I ran a sample from BOL, and it's the same result (error).
Does that sample work for you?

Show quote
"David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
message news:unzfOm20GHA.4796@TK2MSFTNGP03.phx.gbl...
> >"Mark Goldin" <mgol***@ufandd.com> wrote in message
> >news:ew21tZ20GHA.4656@TK2MSFTNGP04.phx.gbl...
>>Here is my statement
> . . .
>>Can you help, please?
>
>
> Please provide DDL and sample data.
> http://www.aspfaq.com/etiquette.asp?id=5006
>
>
>
> David
>
Author
8 Sep 2006 11:19 PM
David Browne
<DIV>&quot;Mark Goldin&quot; &lt;mgol***@ufandd.com&gt; wrote in message
news:uIhe0o20GHA.4392@TK2MSFTNGP04.phx.gbl...</DIV>> Like I said I ran a
sample from BOL, and it's the same result (error).
> Does that sample work for you?
>

What sample?

David
Show quote
> "David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
> message news:unzfOm20GHA.4796@TK2MSFTNGP03.phx.gbl...
>> >"Mark Goldin" <mgol***@ufandd.com> wrote in message
>> >news:ew21tZ20GHA.4656@TK2MSFTNGP04.phx.gbl...
>>>Here is my statement
>> . . .
>>>Can you help, please?
>>
>>
>> Please provide DDL and sample data.
>> http://www.aspfaq.com/etiquette.asp?id=5006
>>
>>
>>
>> David
>>
>
>
Author
9 Sep 2006 1:13 AM
Mark Goldin
BOL has a sample code of using APPLY.
I am copying it into QA and it gives me same error.
Kind of funny.

Show quote
"David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
message news:%235koC150GHA.1292@TK2MSFTNGP03.phx.gbl...
>
>
> <DIV>&quot;Mark Goldin&quot; &lt;mgol***@ufandd.com&gt; wrote in message
> news:uIhe0o20GHA.4392@TK2MSFTNGP04.phx.gbl...</DIV>> Like I said I ran a
> sample from BOL, and it's the same result (error).
>> Does that sample work for you?
>>
>
> What sample?
>
> David
>> "David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
>> message news:unzfOm20GHA.4796@TK2MSFTNGP03.phx.gbl...
>>> >"Mark Goldin" <mgol***@ufandd.com> wrote in message
>>> >news:ew21tZ20GHA.4656@TK2MSFTNGP04.phx.gbl...
>>>>Here is my statement
>>> . . .
>>>>Can you help, please?
>>>
>>>
>>> Please provide DDL and sample data.
>>> http://www.aspfaq.com/etiquette.asp?id=5006
>>>
>>>
>>>
>>> David
>>>
>>
>>
Author
9 Sep 2006 1:26 AM
Kalen Delaney
You've probably already checked this, but please verify your version:

SELECT SERVERPROPERTY('productversion')

--
HTH
Kalen Delaney, SQL Server MVP


Show quote
"Mark Goldin" <markgoldin_2***@yahoo.com> wrote in message
news:%23WqBy060GHA.1588@TK2MSFTNGP02.phx.gbl...
> BOL has a sample code of using APPLY.
> I am copying it into QA and it gives me same error.
> Kind of funny.
>
> "David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
> message news:%235koC150GHA.1292@TK2MSFTNGP03.phx.gbl...
>>
>>
>> <DIV>&quot;Mark Goldin&quot; &lt;mgol***@ufandd.com&gt; wrote in message
>> news:uIhe0o20GHA.4392@TK2MSFTNGP04.phx.gbl...</DIV>> Like I said I ran a
>> sample from BOL, and it's the same result (error).
>>> Does that sample work for you?
>>>
>>
>> What sample?
>>
>> David
>>> "David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
>>> message news:unzfOm20GHA.4796@TK2MSFTNGP03.phx.gbl...
>>>> >"Mark Goldin" <mgol***@ufandd.com> wrote in message
>>>> >news:ew21tZ20GHA.4656@TK2MSFTNGP04.phx.gbl...
>>>>>Here is my statement
>>>> . . .
>>>>>Can you help, please?
>>>>
>>>>
>>>> Please provide DDL and sample data.
>>>> http://www.aspfaq.com/etiquette.asp?id=5006
>>>>
>>>>
>>>>
>>>> David
>>>>
>>>
>>>
>
>
Author
9 Sep 2006 1:30 AM
Mark Goldin
9.00.1399.06
is what I have.

Show quote
"Kalen Delaney" <replies@public_newsgroups.com> wrote in message
news:OlQ$E860GHA.720@TK2MSFTNGP02.phx.gbl...
> You've probably already checked this, but please verify your version:
>
> SELECT SERVERPROPERTY('productversion')
>
> --
> HTH
> Kalen Delaney, SQL Server MVP
>
>
> "Mark Goldin" <markgoldin_2***@yahoo.com> wrote in message
> news:%23WqBy060GHA.1588@TK2MSFTNGP02.phx.gbl...
>> BOL has a sample code of using APPLY.
>> I am copying it into QA and it gives me same error.
>> Kind of funny.
>>
>> "David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
>> message news:%235koC150GHA.1292@TK2MSFTNGP03.phx.gbl...
>>>
>>>
>>> <DIV>&quot;Mark Goldin&quot; &lt;mgol***@ufandd.com&gt; wrote in message
>>> news:uIhe0o20GHA.4392@TK2MSFTNGP04.phx.gbl...</DIV>> Like I said I ran a
>>> sample from BOL, and it's the same result (error).
>>>> Does that sample work for you?
>>>>
>>>
>>> What sample?
>>>
>>> David
>>>> "David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
>>>> message news:unzfOm20GHA.4796@TK2MSFTNGP03.phx.gbl...
>>>>> >"Mark Goldin" <mgol***@ufandd.com> wrote in message
>>>>> >news:ew21tZ20GHA.4656@TK2MSFTNGP04.phx.gbl...
>>>>>>Here is my statement
>>>>> . . .
>>>>>>Can you help, please?
>>>>>
>>>>>
>>>>> Please provide DDL and sample data.
>>>>> http://www.aspfaq.com/etiquette.asp?id=5006
>>>>>
>>>>>
>>>>>
>>>>> David
>>>>>
>>>>
>>>>
>>
>>
>
>
Author
9 Sep 2006 1:42 AM
Kalen Delaney
What's your compatibility level:

EXEC sp_dbcmptlevel 'your_database'

--
HTH
Kalen Delaney, SQL Server MVP


Show quote
"Mark Goldin" <markgoldin_2***@yahoo.com> wrote in message
news:eMqrY%2360GHA.4108@TK2MSFTNGP04.phx.gbl...
> 9.00.1399.06
> is what I have.
>
> "Kalen Delaney" <replies@public_newsgroups.com> wrote in message
> news:OlQ$E860GHA.720@TK2MSFTNGP02.phx.gbl...
>> You've probably already checked this, but please verify your version:
>>
>> SELECT SERVERPROPERTY('productversion')
>>
>> --
>> HTH
>> Kalen Delaney, SQL Server MVP
>>
>>
>> "Mark Goldin" <markgoldin_2***@yahoo.com> wrote in message
>> news:%23WqBy060GHA.1588@TK2MSFTNGP02.phx.gbl...
>>> BOL has a sample code of using APPLY.
>>> I am copying it into QA and it gives me same error.
>>> Kind of funny.
>>>
>>> "David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
>>> message news:%235koC150GHA.1292@TK2MSFTNGP03.phx.gbl...
>>>>
>>>>
>>>> <DIV>&quot;Mark Goldin&quot; &lt;mgol***@ufandd.com&gt; wrote in
>>>> message news:uIhe0o20GHA.4392@TK2MSFTNGP04.phx.gbl...</DIV>> Like I
>>>> said I ran a sample from BOL, and it's the same result (error).
>>>>> Does that sample work for you?
>>>>>
>>>>
>>>> What sample?
>>>>
>>>> David
>>>>> "David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
>>>>> message news:unzfOm20GHA.4796@TK2MSFTNGP03.phx.gbl...
>>>>>> >"Mark Goldin" <mgol***@ufandd.com> wrote in message
>>>>>> >news:ew21tZ20GHA.4656@TK2MSFTNGP04.phx.gbl...
>>>>>>>Here is my statement
>>>>>> . . .
>>>>>>>Can you help, please?
>>>>>>
>>>>>>
>>>>>> Please provide DDL and sample data.
>>>>>> http://www.aspfaq.com/etiquette.asp?id=5006
>>>>>>
>>>>>>
>>>>>>
>>>>>> David
>>>>>>
>>>>>
>>>>>
>>>
>>>
>>
>>
>
>
Author
9 Sep 2006 1:56 AM
Mark Goldin
The current compatibility level is 80.

Show quote
"Kalen Delaney" <replies@public_newsgroups.com> wrote in message
news:uyMv4E70GHA.1256@TK2MSFTNGP04.phx.gbl...
> What's your compatibility level:
>
> EXEC sp_dbcmptlevel 'your_database'
>
> --
> HTH
> Kalen Delaney, SQL Server MVP
>
>
> "Mark Goldin" <markgoldin_2***@yahoo.com> wrote in message
> news:eMqrY%2360GHA.4108@TK2MSFTNGP04.phx.gbl...
>> 9.00.1399.06
>> is what I have.
>>
>> "Kalen Delaney" <replies@public_newsgroups.com> wrote in message
>> news:OlQ$E860GHA.720@TK2MSFTNGP02.phx.gbl...
>>> You've probably already checked this, but please verify your version:
>>>
>>> SELECT SERVERPROPERTY('productversion')
>>>
>>> --
>>> HTH
>>> Kalen Delaney, SQL Server MVP
>>>
>>>
>>> "Mark Goldin" <markgoldin_2***@yahoo.com> wrote in message
>>> news:%23WqBy060GHA.1588@TK2MSFTNGP02.phx.gbl...
>>>> BOL has a sample code of using APPLY.
>>>> I am copying it into QA and it gives me same error.
>>>> Kind of funny.
>>>>
>>>> "David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
>>>> message news:%235koC150GHA.1292@TK2MSFTNGP03.phx.gbl...
>>>>>
>>>>>
>>>>> <DIV>&quot;Mark Goldin&quot; &lt;mgol***@ufandd.com&gt; wrote in
>>>>> message news:uIhe0o20GHA.4392@TK2MSFTNGP04.phx.gbl...</DIV>> Like I
>>>>> said I ran a sample from BOL, and it's the same result (error).
>>>>>> Does that sample work for you?
>>>>>>
>>>>>
>>>>> What sample?
>>>>>
>>>>> David
>>>>>> "David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote
>>>>>> in message news:unzfOm20GHA.4796@TK2MSFTNGP03.phx.gbl...
>>>>>>> >"Mark Goldin" <mgol***@ufandd.com> wrote in message
>>>>>>> >news:ew21tZ20GHA.4656@TK2MSFTNGP04.phx.gbl...
>>>>>>>>Here is my statement
>>>>>>> . . .
>>>>>>>>Can you help, please?
>>>>>>>
>>>>>>>
>>>>>>> Please provide DDL and sample data.
>>>>>>> http://www.aspfaq.com/etiquette.asp?id=5006
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> David
>>>>>>>
>>>>>>
>>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
9 Sep 2006 2:50 AM
Kalen Delaney
It needs to be 90 to use APPLY.

--
HTH
Kalen Delaney, SQL Server MVP


Show quote
"Mark Goldin" <markgoldin_2***@yahoo.com> wrote in message
news:ORkduM70GHA.4108@TK2MSFTNGP04.phx.gbl...
> The current compatibility level is 80.
>
> "Kalen Delaney" <replies@public_newsgroups.com> wrote in message
> news:uyMv4E70GHA.1256@TK2MSFTNGP04.phx.gbl...
>> What's your compatibility level:
>>
>> EXEC sp_dbcmptlevel 'your_database'
>>
>> --
>> HTH
>> Kalen Delaney, SQL Server MVP
>>
>>
>> "Mark Goldin" <markgoldin_2***@yahoo.com> wrote in message
>> news:eMqrY%2360GHA.4108@TK2MSFTNGP04.phx.gbl...
>>> 9.00.1399.06
>>> is what I have.
>>>
>>> "Kalen Delaney" <replies@public_newsgroups.com> wrote in message
>>> news:OlQ$E860GHA.720@TK2MSFTNGP02.phx.gbl...
>>>> You've probably already checked this, but please verify your version:
>>>>
>>>> SELECT SERVERPROPERTY('productversion')
>>>>
>>>> --
>>>> HTH
>>>> Kalen Delaney, SQL Server MVP
>>>>
>>>>
>>>> "Mark Goldin" <markgoldin_2***@yahoo.com> wrote in message
>>>> news:%23WqBy060GHA.1588@TK2MSFTNGP02.phx.gbl...
>>>>> BOL has a sample code of using APPLY.
>>>>> I am copying it into QA and it gives me same error.
>>>>> Kind of funny.
>>>>>
>>>>> "David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
>>>>> message news:%235koC150GHA.1292@TK2MSFTNGP03.phx.gbl...
>>>>>>
>>>>>>
>>>>>> <DIV>&quot;Mark Goldin&quot; &lt;mgol***@ufandd.com&gt; wrote in
>>>>>> message news:uIhe0o20GHA.4392@TK2MSFTNGP04.phx.gbl...</DIV>> Like I
>>>>>> said I ran a sample from BOL, and it's the same result (error).
>>>>>>> Does that sample work for you?
>>>>>>>
>>>>>>
>>>>>> What sample?
>>>>>>
>>>>>> David
>>>>>>> "David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote
>>>>>>> in message news:unzfOm20GHA.4796@TK2MSFTNGP03.phx.gbl...
>>>>>>>> >"Mark Goldin" <mgol***@ufandd.com> wrote in message
>>>>>>>> >news:ew21tZ20GHA.4656@TK2MSFTNGP04.phx.gbl...
>>>>>>>>>Here is my statement
>>>>>>>> . . .
>>>>>>>>>Can you help, please?
>>>>>>>>
>>>>>>>>
>>>>>>>> Please provide DDL and sample data.
>>>>>>>> http://www.aspfaq.com/etiquette.asp?id=5006
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> David
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
9 Sep 2006 1:44 AM
Kalen Delaney
The code in the BOL APPLY sample worked for me.

--
HTH
Kalen Delaney, SQL Server MVP


Show quote
"Mark Goldin" <markgoldin_2***@yahoo.com> wrote in message
news:eMqrY%2360GHA.4108@TK2MSFTNGP04.phx.gbl...
> 9.00.1399.06
> is what I have.
>
> "Kalen Delaney" <replies@public_newsgroups.com> wrote in message
> news:OlQ$E860GHA.720@TK2MSFTNGP02.phx.gbl...
>> You've probably already checked this, but please verify your version:
>>
>> SELECT SERVERPROPERTY('productversion')
>>
>> --
>> HTH
>> Kalen Delaney, SQL Server MVP
>>
>>
>> "Mark Goldin" <markgoldin_2***@yahoo.com> wrote in message
>> news:%23WqBy060GHA.1588@TK2MSFTNGP02.phx.gbl...
>>> BOL has a sample code of using APPLY.
>>> I am copying it into QA and it gives me same error.
>>> Kind of funny.
>>>
>>> "David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
>>> message news:%235koC150GHA.1292@TK2MSFTNGP03.phx.gbl...
>>>>
>>>>
>>>> <DIV>&quot;Mark Goldin&quot; &lt;mgol***@ufandd.com&gt; wrote in
>>>> message news:uIhe0o20GHA.4392@TK2MSFTNGP04.phx.gbl...</DIV>> Like I
>>>> said I ran a sample from BOL, and it's the same result (error).
>>>>> Does that sample work for you?
>>>>>
>>>>
>>>> What sample?
>>>>
>>>> David
>>>>> "David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
>>>>> message news:unzfOm20GHA.4796@TK2MSFTNGP03.phx.gbl...
>>>>>> >"Mark Goldin" <mgol***@ufandd.com> wrote in message
>>>>>> >news:ew21tZ20GHA.4656@TK2MSFTNGP04.phx.gbl...
>>>>>>>Here is my statement
>>>>>> . . .
>>>>>>>Can you help, please?
>>>>>>
>>>>>>
>>>>>> Please provide DDL and sample data.
>>>>>> http://www.aspfaq.com/etiquette.asp?id=5006
>>>>>>
>>>>>>
>>>>>>
>>>>>> David
>>>>>>
>>>>>
>>>>>
>>>
>>>
>>
>>
>
>
Author
8 Sep 2006 5:03 PM
Mark Goldin
I ran sample form BOL, and I am getting same error.

Show quote
"David Browne" <davidbaxterbrowne no potted m***@hotmail.com> wrote in
message news:%23yyEVL20GHA.1040@TK2MSFTNGP06.phx.gbl...
>
>
> <DIV>&quot;Mark Goldin&quot; &lt;mgol***@ufandd.com&gt; wrote in message
> news:ewcLH%2310GHA.4796@TK2MSFTNGP03.phx.gbl...</DIV>> Can I create a
> function that can be a part of a SELECT statement and it
>> would be capable of accepting a parameter that is a column name from one
>> of the tables in the statement?
>>
>
> Yes, that's basically what functions are for.
>
> Although if it is a Table-Valued function this only works on SQL 2005
> using the APPLY operators.
>
> David

AddThis Social Bookmark Button