Showing posts with label function. Show all posts
Showing posts with label function. Show all posts

Friday, March 23, 2012

reformatting DATE

I currently have a date column that draws from the now() function in my
asp script. The date looks like this:

2/5/2004 10:09:52 AM

As you can see, there is the day and the time data all in the same
string.

What I would like to do is run a group by clause that groups
all the dates that are on the same day togeather. But how do I seperate
this data in SQL? I know there are VB functions that can do this, but in
order for the group function to work when running a sql statement, I
have to do it in SQL itself. Does anyone know how this is done?

Thank you!

Bill

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!"Bill" <BillZimmerman@.gospellight.com> wrote in message
news:4023cc79$0$196$75868355@.news.frii.net...
> I currently have a date column that draws from the now() function in my
> asp script. The date looks like this:
> 2/5/2004 10:09:52 AM
> As you can see, there is the day and the time data all in the same
> string.
> What I would like to do is run a group by clause that groups
> all the dates that are on the same day togeather. But how do I seperate
> this data in SQL? I know there are VB functions that can do this, but in
> order for the group function to work when running a sql statement, I
> have to do it in SQL itself. Does anyone know how this is done?
> Thank you!
> Bill
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

I'm not completely sure what you're looking for, but perhaps something like
this?

select convert(char(8), DateColumn, 112) as 'Day', sum(SomeColumn) as
'Total'
from dbo.MyTable
group by convert(char(8), DateColumn, 112)

Simon

Wednesday, March 21, 2012

referencing to a function..

I was created a function named aa.

It is possible to reference to it without using the dbo. prnounce ?

eg: select aa(), not select dbo.aa()

thanks,

ViktorThe owner name is required for scalar UDFs but not for table-valued UDFs.
Otherwise it could be difficult to identify from the syntax that a scalar
UDF was being referenced.

--
David Portas
SQL Server MVP
--

Tuesday, March 20, 2012

referencing fields in the code window

Hi, how do I reference a report field in a custom function which is written
in the code window (Report Properties/code tab)? i.e.
Function Something
If Fields!FIELD1_Company.Value = Nothing Then
Return ""
End If
End Function
This example will not work but it's similar to my needs
Thanks
NPSend the field value as a parameter to your function. i.e. re-write the
function as:
Function SomeFunction(byVal MyFieldValue as datatype) as datatype
if MyFieldValue is nothing
...
return ...
End Function
In your report expression, just call the function:
=Code.SomeFunction(Fields!MyField.Value)
Charles Kangai, MCT, MCDBA
"slk55guy" wrote:
> Hi, how do I reference a report field in a custom function which is written
> in the code window (Report Properties/code tab)? i.e.
> Function Something
> If Fields!FIELD1_Company.Value = Nothing Then
> Return ""
> End If
> End Function
> This example will not work but it's similar to my needs
> Thanks
> NP
>|||Thanks Charles, by the way how are you? I was on one of your DTS courses a
couple of years ago in the city. Small world eh?
I think this will work but there is another post (converting crystal code) I
put up here and basically I'm trying to get the same functionality as I would
in a Crystal function.
Happy Christmas
NP
"Charles Kangai" wrote:
> Send the field value as a parameter to your function. i.e. re-write the
> function as:
> Function SomeFunction(byVal MyFieldValue as datatype) as datatype
> if MyFieldValue is nothing
> ...
> return ...
> End Function
> In your report expression, just call the function:
> =Code.SomeFunction(Fields!MyField.Value)
> Charles Kangai, MCT, MCDBA
>
> "slk55guy" wrote:
> > Hi, how do I reference a report field in a custom function which is written
> > in the code window (Report Properties/code tab)? i.e.
> >
> > Function Something
> > If Fields!FIELD1_Company.Value = Nothing Then
> > Return ""
> > End If
> > End Function
> >
> > This example will not work but it's similar to my needs
> >
> > Thanks
> >
> > NP
> >|||Hi,
It should work. I am using something similar myself.
I did a demonstration and some conversations for a customer earlier this
week. The developers are all Crystal users, and they were so impressed with
Reporting Services that they are going to migrate all their sites in UK,
Italy, USA, and Denmark to RS within the next few weeks.
Great to come across you again - we will be running a Reporting Services
course from the end of Feb. I am the author. Check with Learning Tree.
Merry Christmas!
Charles
"slk55guy" wrote:
> Thanks Charles, by the way how are you? I was on one of your DTS courses a
> couple of years ago in the city. Small world eh?
> I think this will work but there is another post (converting crystal code) I
> put up here and basically I'm trying to get the same functionality as I would
> in a Crystal function.
> Happy Christmas
> NP
> "Charles Kangai" wrote:
> > Send the field value as a parameter to your function. i.e. re-write the
> > function as:
> >
> > Function SomeFunction(byVal MyFieldValue as datatype) as datatype
> > if MyFieldValue is nothing
> > ...
> > return ...
> > End Function
> >
> > In your report expression, just call the function:
> > =Code.SomeFunction(Fields!MyField.Value)
> >
> > Charles Kangai, MCT, MCDBA
> >
> >
> > "slk55guy" wrote:
> >
> > > Hi, how do I reference a report field in a custom function which is written
> > > in the code window (Report Properties/code tab)? i.e.
> > >
> > > Function Something
> > > If Fields!FIELD1_Company.Value = Nothing Then
> > > Return ""
> > > End If
> > > End Function
> > >
> > > This example will not work but it's similar to my needs
> > >
> > > Thanks
> > >
> > > NP
> > >

Monday, March 12, 2012

Referencing a CLR DLL in a Custom Task

Is there a way you can reference a prebuilt CLR function in a custom dataflow task?

The CLR and the custom dataflow task are one in the same. The reason that I'm designing the custom task is that I find that it's time consuming to make a call to the database to retrieve a function to work on something that's already in memory. Also, another reason is that if the code needs to be updated, it doesn't have to be done in 2 places allowing for less confusion.

I tried adding a reference to the CLR function in my SSIS dataflow task, but when I try running it in SSIS, I get the error saying it cannot use a SQL CLR defined task in the package which I believe is due to this reference in the CLR code:

[Microsoft.SqlServer.Server.SqlFunction]
public static string toCase(string text, string caseType)

Is there a way to circumvent the [...SqlFunction] line of code when the DLL is referenced by an SSIS dataflow task, or do I just have to deal with having 2 copies of the same code?

Thanks in advance!

Nevermind, I guess the only way to do it is to separate the function as a core class and then create a CLR wrapper and then an SSIS wrapper.

Monday, February 20, 2012

Reduce function call in a Select statment

I have a stored procedure that is something like this :
SELECT TableA.*, value = dbo.functionA(TableA.id, x,x)
FROM TableA
WHERE TableA.id = 'SomeValue'
AND dbo.functionA(TableA.key, x,x) > 0
This procedure is executed over 1000 times in a hour, and the function calls
in the proc is called twice each time this procedure is called.
Is there a way to rewrite this statement so that the function call is only
made once'
Thanks
MikeSee if you can rewrite without the function - that's the fastest. Failing
that:
select
*
from
(
select
*
, value = dbo.functionA(id, x,x)
from
TableA
where
id = 'SomeValue'
) as x
where
value > 0
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"Mike" <y4forums.t.mdgoyal@.xoxy.net> wrote in message
news:%23oPVPH4UGHA.2492@.TK2MSFTNGP11.phx.gbl...
I have a stored procedure that is something like this :
SELECT TableA.*, value = dbo.functionA(TableA.id, x,x)
FROM TableA
WHERE TableA.id = 'SomeValue'
AND dbo.functionA(TableA.key, x,x) > 0
This procedure is executed over 1000 times in a hour, and the function calls
in the proc is called twice each time this procedure is called.
Is there a way to rewrite this statement so that the function call is only
made once'
Thanks
Mike|||Thanks
"Tom Moreau" <tom@.dont.spam.me.cips.ca> wrote in message
news:OJBQ%23N4UGHA.4348@.TK2MSFTNGP09.phx.gbl...
> See if you can rewrite without the function - that's the fastest. Failing
> that:
> select
> *
> from
> (
> select
> *
> , value = dbo.functionA(id, x,x)
> from
> TableA
> where
> id = 'SomeValue'
> ) as x
> where
> value > 0
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada
> www.pinpub.com
> .
> "Mike" <y4forums.t.mdgoyal@.xoxy.net> wrote in message
> news:%23oPVPH4UGHA.2492@.TK2MSFTNGP11.phx.gbl...
> I have a stored procedure that is something like this :
> SELECT TableA.*, value = dbo.functionA(TableA.id, x,x)
> FROM TableA
> WHERE TableA.id = 'SomeValue'
> AND dbo.functionA(TableA.key, x,x) > 0
> This procedure is executed over 1000 times in a hour, and the function
> calls
> in the proc is called twice each time this procedure is called.
> Is there a way to rewrite this statement so that the function call is only
> made once'
> Thanks
> Mike
>