SQL-2000 Stored Procesure Or Function

Jul 20, 2005

Hi Group...

In one of my tables in a SQL-2000 db, do I have a calculated column calling
a user defined function.

That's not a problem, but now I need to update another column in the same
table form this udf.

It seems not to be possible in SQL-2000, so how is such thing normally done
?

Do I need to call e stored procedure from within the function, with the
nessesary parameters, and then let this stored procedure perform the update,
or is it a better idea to change the function used in the computed column to
a stored procedure ?

If so, how am I programming the call to the procedure?
Something similar to the function-call which is done like:

CREATE TABLE table1 (
column1 int AS dbo.fn_calculate_something (parameter1, parameter2),
column2 .....
column3.....
)

Thanks in advance.

Steen

View 1 Replies


ADVERTISEMENT

Mod Function In SQL 2000

Feb 27, 2004

I need to use the mod function on a numeric field with 2digits decimal.
I was told that SQL server does not support mod on a decimal number.

Is it correct? If yes, is there any way around this?

Thanks in advance

View 14 Replies View Related

SQL 2000 - Substring Function

Jun 20, 2004

Hello,

I want to select the characters before "-" from Column A.
For example:
12345-HSC
222-ABC

I'd would like to select it as:
12345
222

Please Help!!!!!!!!!!!!!!!!!!!!! :confused:

View 3 Replies View Related

CLR Function Equivalent In SQL 2000

Jan 31, 2008


Hi,
I have successfully created a CLR function (C#) in SQL 2005 and call it from a stored procedure. I need to be able to provide the same functionality for SQL 2000 servers. Is this at all possible? I have read loads of conflicting information on the web about using COM to access the dll €“ can it be done or not? The function accepts serveral input parameters and internally access the data store using a context connection and a datareader.
Thanks.

View 6 Replies View Related

Only Functions And Extended Stored Procedures Can Be Executed From Within A Function. Sp_executesql Is A Extended Stored Prod

May 15, 2008

i have created the folowing function but keep geting an error.

Only functions and extended stored procedures can be executed from within a function.

Why am i getting this error!

Create Function myDateAdd
(@buildd nvarchar(4), @avdate as nvarchar(25))
Returns nvarchar(25)
as
Begin
declare @ret nvarchar(25)
declare @sqlval as nvarchar(3000)

set @sqlval = 'select ''@ret'' = max(realday) from (
select top '+ @buildd +' realday from v_caltable where realday >= '''+ @avdate +''' and prod = 1 )a'

execute sp_executesql @sqlval
return @ret
end

View 3 Replies View Related

Calander In SQLSERVER 2000(Using Function)

Mar 1, 2005

I had built a one calander in SQLSERVER

View 1 Replies View Related

Recresive Function In Sql Server 2000

Aug 5, 2005

My Table Structure is

Mem IDNameBoss ID
=======================
1Mohan0
2Raju1
3Prem1
4Priya2
5Sara3
6Ray4
7Chan0

I need to procedure to retrive all the down Members by giving a member number.

I have created a recresive function to achive this but at one stage it's giving error(above 32 level it's throwing an error). So i want a procedure which populates the temp. table with the required Information.

View 2 Replies View Related

Need Help With Raiserror Function In Ado.net Mssql 2000

Dec 7, 2007

I have a stored procedure that raises an error just fine, but the problem is when i want to catch that particular error in client code, how do i go able doing so, i want to display a message in a label when that particular error occurs.

right now all i know about the raiserror function is RAISERROR("Message", Severity, Stage) how do i give it number so i can catch it in code?

ALTER Stored Procedure [dbo].[spName]

..............................................
...............................................


IF (@DummySetKey IS NULL)

BEGIN
RAISERROR('Error: This setkey number does not exist as a valid entry.', 11, 1);

SELECT @ErrCode = @@ERROR
END

IF @ErrCode <> 0 GOTO ERROR_HANDLER

ERROR_HANDLER:
ROLLBACK TRANSACTION
RETURN @@ERROR



client code:

Public Function ExecuteNonQuery(byval connstr as string) as boolean

dim conn as new SqlConnection(connstr)
Dim cmd as sqlCommand(spName, conn)
cmd.CommandType = CommandType.StoredProcedure

conn.Open()

try

dim rowsAffected as Integer = cmd.ExecuteNonQuery()

If ex.ErrorCode = 5021 Then
' display in textbox
Else
Throw
End If
Finally
conn.Close()
end try

if rowsAffected > 0 Then
return true
else
return false
end if
End Function

View 1 Replies View Related

Forcing Function Recompilation In SQL 2000

Sep 12, 2006

A stored procedure in the cache is automatically recompiled when a table it refers to has a table structure change. User defined functions are not. Here's a simplified code sample:

set nocount on
go

create table tmpTest (a int, b int, c int)

insert into tmpTest (a, b, c) values (1, 2, 3)
insert into tmpTest (a, b, c) values (2, 3, 4)
go

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fTest]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[fTest]
GO

CREATE FUNCTION dbo.fTest (@a int)
RETURNS TABLE
AS
RETURN (SELECT * from tmpTest where a = @a)
GO

select * from fTest(1)

CREATE TABLE dbo.Tmp_tmpTest
(
a int NULL,
b int NULL,
d int NULL,
c int NULL
) ON [PRIMARY]
IF EXISTS(SELECT * FROM dbo.tmpTest)
EXEC('INSERT INTO dbo.Tmp_tmpTest (a, b, c)
SELECT a, b, c FROM dbo.tmpTest TABLOCKX')
DROP TABLE dbo.tmpTest
EXECUTE sp_rename N'dbo.Tmp_tmpTest', N'tmpTest', 'OBJECT'

select * from fTest(1)

drop table tmpTest

Running it, the output is:

a b c
----------- ----------- -----------
1 2 3

Caution: Changing any part of an object name could break scripts and stored procedures.
The OBJECT was renamed to 'tmpTest'.
a b c
----------- ----------- -----------
1 2 NULL


(I know that "select *" is bad, but it's a lot of legacy code that I'm working with here, and that's how it's written.)

The function doesn't detect that the table has changed in structure, or even that there is no longer a dependency on tmpTest. (Appending a column rather than inserting has the same effect, in that only the first 3 columns are returned.)

DBCC FREEPROCCACHE has no effect, not that I really expected it to, but you never know...

Is there any way, other than dropping and recreating, to force a recompilation of a particular function in memory, or perhaps all functions?

Thanks in anticipation.

Tom



View 6 Replies View Related

MSSQL 2000: How Can We Track Table/sp/function Changes?

May 19, 2006

My company would like to start keeping track of everytime a table, stored procedure, or function is changed.

What is the best way to do this?

View 4 Replies View Related

Transact SQL :: Duplicate PIVOT Function In 2000

Jul 1, 2015

I have a query that uses the PIVOT function and works fine in SQL 2012.  I've been asked to move the query to a database that has the compatibility level set to 80(SQL 2000).  I receive an "Incorrect syntax near" error when I try to excute the query on the SQL 2000 database.  I would like to duplicate the exiting PIVOT functionality in SQL 2000.The existing query retrieves employee names and the order that the employee should be displayed from a table.  The names will appear on the report according to the order that is retrieved from the database.  Also, the users have requested that only 5 names appear on each row of the report.  This is why the PIVOT function was needed.  Below is an example of how the existing query works.

Table
CREATE TABLE [dbo].[EmpGuest](
 [Guest_ID] [int] NOT NULL,
 [Guest_Name] [varchar](80) NULL,
 [Display_Order] [int] NULL
) ON [PRIMARY]

[code]....

View 4 Replies View Related

Execute Stored Procedure Y Asynchronously From Stored Proc X Using SQL Server 2000

Oct 14, 2007

I am calling a stored procedure (say X) and from that stored procedure (i mean X) i want to call another stored procedure (say Y)asynchoronoulsy. Once stored procedure X is completed then i want to return execution to main program. In background, Stored procedure Y will contiue his work. Please let me know how to do that using SQL Server 2000 and ASP.NET 2.

View 3 Replies View Related

SQL Server 2000 SP3 Installed - Problem With Convert() Function

Sep 21, 2004

I am facing a problem with Convert function in SQL server 2000 with sp3 installed , Japanese version

In sql server 2000 (sp1 installed) Japanese version, the convert(datetime,,111) gives me date in the format yyyy-mm-dd hh:min:sec


But in sql server 2000 (sp3 instaled) Japanese version, the convert(datetime, ,111) gives me date in the format yyyy-mm-dd.

I need the hh:min:sec to do an exact date comparison.


The problem is solved if I use Convert(datetime,,120).

Any pointers on the root cause of why the problem occurs with convert() function once sp3 is installed?

View 1 Replies View Related

User Defined Aggregate Function In SQL Server 2000?

Feb 19, 2008

Is it possible to define your own function? If so could you give me an example.

Keep in mind that I said in SQL Server 2000. I want no CLR SQL Server 2005 solutions.

Cheers,
David

View 1 Replies View Related

What Is Equivalent Of Format(date) Function Of MS Access In MS Sql Server 2000

Jul 20, 2005

Hi All,I am facing a problem with a sql what i used in MS Access but its notreturning the same result in MS Sql Server 2000. Here i am giving thesql:SELECT TOP 3 format( MY_DATE, "dddd mm, yyyy" ) FROM MY_TAB WHEREMY_ID=1The above sql in ACCESS return me the date in below format in onecolumn:Friday 09, 2003But in Sql server 2000 i am not getting the same format eventhough iam using convert function, date part function etc.Please if you find the solution would be helpful for me..ThanksHoque

View 3 Replies View Related

What's The Equivalen Function Of StrConv ([FirstName] , 3 ) In ACCESS In Sql Server 2000?

Jul 20, 2005

HI,i got a problem while using StrConv function in sql server.My requirement is:-suppose in a name field i have "jhon smith" Now i want to run a sqlwhich will give me the result like "Jhon Smith"--which means uppercase first.Now i am running a query like below which is giving me "Jhon smith"but i want "Jhon Smith".SELECT [CustomerID] ,upper(left(firstname,1)) + lower(right(firstname,len(firstname)-1)) AS [FirstName_] from my_table;But the above query is not giving me the right result. Pleasesuggest...ThanksHoque

View 2 Replies View Related

Stored Function Automation

Aug 16, 2006

Hey,How can I schedule a stored function to run atleast once a day, other than by having it as a scheduled task on the server?Sql Server 2000Thanks

View 3 Replies View Related

Function Vs Stored Procedure

May 1, 2004

I know this is a stupid question (actually, maybe its not..?)

They seem to be identical in some ways, but not available to the outside world. what are some differences?

View 3 Replies View Related

Function From Stored Procedure

Nov 22, 2007

Hi Everyone,

i want to create a function in Stored procedure and then call this function
that returns true or false from a stored procedure .
is this possible?

please help me if you know something that can help me.

thanks

Tvin

View 2 Replies View Related

Stored Function Problem

Jan 30, 2008

Hi,

when i run this code, function does not get through; should i use procedure or can this be done within function


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


CREATE function [dbo].[fn_user_product_groups]
(@userid as int) returns varchar (1000)
as
begin
declare @product_groups as varchar(900);
set @product_groups = '';

select @product_groups =

userid
,group1
,group2
,group3
from
(select
userid
,SUM(CASE WHEN groups.id = 6 THEN 1 ELSE 0 END) AS group1
,SUM(CASE WHEN groups.id = 8 THEN 1 ELSE 0 END) AS group2
,SUM(CASE WHEN groups.id = 9 THEN 1 ELSE 0 END) AS group3

from
groups_products as groups
join users as u
on u.userid = groups.userid

where
u.userid = @userid
and condition1 = 1
and condition2 = 2

group by userid) as a

group by

userid
,group1
,group2
,group3

return @product_groups;
end


thank you for help :)

View 5 Replies View Related

When To Use A Function And When To Use A Stored Procedure.

Oct 28, 2006

Hi,

I thought that procedures do not return a value: well they only return a 1 or 0 depending on whether the procedure executed correctly. Functions are what you're supposed to use when you want to get a result set of some sort: ie a table or a scalar value.

Apparently that is not the case becuase you can return values from procedures. I've attempted to find out what the differences are between the two and when it is appropriate to use a procedure and when it is appropriate to use a function but I'm still unsure. Can someone please tell me the difference.

Thanks.

Przemek

View 16 Replies View Related

Differance Stored Procedure And Function

Nov 26, 2006

hello
what is differance beetween stored-procedure and Function
when use of stored rpocedure and function

View 1 Replies View Related

Diff. B/w Stored Procedures And Function??

Nov 28, 2006

Diff. b/w Stored Procedures and Function??
 
When any of them is appropriate to use?

View 2 Replies View Related

Call Function From Stored Procedure

Jan 19, 2007

Hi All,
I'll admit that I'm not the greatest at stored procedure/functions but I want to learn as much as possible.  So I have two questions:
1) I had VS2005 autogenerate a sqldatasource that created Select/Insert/Update stored procedures.  When Updating a record and calling the stored procedure, I want to query another table (we'll call it tblBatchNo) that has only one record, Batchno.  I want to put that current batchno into the Update statement and update the record with the current batchno.  Can someone point me in the right direction?  Remember that I'm still a beginner on this subject.
2) Can someone provide any links to online tutorials on t-sql?
Thanks in advance.
Curtis

View 2 Replies View Related

Calling A Function From A Stored Procedure

Oct 26, 2007

Hello all,
I'm trying to construct a select statement in a stored procedure that filters based on the returned values of a number of functions.  My function works fine, but when I try to call the function from the stored procedure I get an error.
I'm going to try explain the thought process behind what I'm doing.  Hope I make enough sense.The purpose of the stored procedure is to perform a wildcard search on a tool.  The tool contains a number of FK that link to different tables (e.g., manufacturer, vendor).  So I'm creating functions that also search the manufacturer and vendor and return the matching IDs.
Example of tool SELECT statement:SELECT tool_number, tool_description
FROM tool
WHERE tool_manufacturer IN (UDFmanufacturer_SearchName(@search_string)
This gives me an error:'UDFmanufacturer_SearchName' is not a recognized built-in function name.
Function code (removed some wrapping code for simplicity):SELECT manufacturer_id
FROM manufacturer
WHERE manufacturer_name LIKE '%' + @search_string + '%'These statements both work if I run a independent query: SELECT *
FROM UDFmanufacturer_SearchName('mol')  SELECT *
FROM tool
WHERE tool_manufacturer IN (SELECT *FROM UDFmanufacturer_SearchName('mol')) This code fails:SELECT *
FROM ato_tool
WHERE ato_tool_manufacturer IN (UDFmanufacturer_SearchName('mol'))
 I'm stuck.  I haven't been able to find anything that shows me where I'm going wrong.  Any thoughts or suggestions are appreciated. Thanks,Jay

View 4 Replies View Related

Stored Procedure - Date Function

Jul 28, 2005

Hi, I ran into some problem here. The case scenerio is supposed to be like this:

- Each member can only make one appointment at any one time and only
make another appointment after the existing appointment expired.
- Each member is allowed to make an appointment at any time and must be at least 5 days in advance.

I managed to do the reservation for at least 5 days in advance but I
can't allow the member to make only one appointment. The member can
keep making appointments even though the existing appointment has not
expired. Can someone pls help? Thanks!


ALTER PROCEDURE spReserveAppt(@AppDate DATETIME, @AppTime CHAR(4), @MemNRIC CHAR(9))
AS

BEGIN
IF NOT EXISTS(SELECT MemNRIC FROM DasMember WHERE MemNRIC = @MemNRIC)
    RETURN -300

BEGIN
IF EXISTS
     (SELECT COUNT(@MemNRIC)
    FROM DasAppointment   
    WHERE (DATEDIFF(DAY, GETDATE(), @AppDate) < 5)
    GROUP BY MemNRIC
    HAVING COUNT(@MemNRIC) <> 0)
    RETURN -301

ELSE IF EXISTS
    (SELECT MemNRIC
    FROM DasAppointment   
    WHERE (DATEDIFF(DAY, @AppDate ,GETDATE()) > GETDATE()))
    RETURN -302

END
END

INSERT INTO DasAppointment(AppDate, AppTime, MemNRIC) VALUES (@AppDate, @AppTime, @MemNRIC)

IF @@ERROR <> 0
    RETURN @@ERROR

RETURN

DECLARE @status int
EXEC @status = spReserveAppt '2005-08-16', '1900', 'S1256755J'
SELECT 'Status' = @status

View 2 Replies View Related

How To Call A Function In Stored Procedure

Sep 12, 2012

How to call a sql function in stored procedure using Sqlserver 2008?

View 4 Replies View Related

RESOLVED: Stored Procedure Of Function?

Aug 16, 2006

I have a select statement like this. Notice that I am doing the same calculation on different fields. Is it possible I can make this, in coding terms, a fucntion; so I can call it when I like (this query) and just provide the field.

Example: select field1, test_field = secs_to_hhmmss(TALK_TIME) from ...

SELECT dbo.date_table.real_date, dbo.time_table.hh,
COUNT(dbo.CALLDETAIL.id) as NumOfCalls,
TalkTime =
CASE WHEN CAST(SUM(TALK_TIME) AS INTEGER)/3600<10 THEN '0' ELSE '' END
+ RTRIM(CAST(SUM(TALK_TIME) AS INTEGER)/3600)
+ ':' + RIGHT('0'+RTRIM((CAST(SUM(TALK_TIME) AS INTEGER) % 3600) / 60),2)
+ ':' + RIGHT('0'+RTRIM((CAST(SUM(TALK_TIME) AS INTEGER) % 3600) % 60),2),
HoldTime =
CASE WHEN CAST(SUM(HOLD_TIME) AS INTEGER)/3600<10 THEN '0' ELSE '' END
+ RTRIM(CAST(SUM(HOLD_TIME) AS INTEGER)/3600)
+ ':' + RIGHT('0'+RTRIM((CAST(SUM(HOLD_TIME) AS INTEGER) % 3600) / 60),2)
+ ':' + RIGHT('0'+RTRIM((CAST(SUM(HOLD_TIME) AS INTEGER) % 3600) % 60),2),

View 3 Replies View Related

ASP/SQL Stored Procedure/ASP Function Error

Jul 20, 2007

Hey I have the following Stored Procedure


CREATE PROCEDURE spGetOrderCount
(
@search varchar(1000) = default
)

AS

SET NOCOUNT ON

/* Setup search string */
IF (@search <> '')
BEGIN
SET @search = 'WHERE' + @search
END


/* Create a temporary table */
CREATE TABLE #TempTable
(
row int IDENTITY,
totalCount int
)

/* Insert the search results into query */
EXEC
(
'INSERT INTO #TempTable([totalCount])' +
'SELECT COUNT(*) AS totalCount ' +
'FROM tblOrders' + @search
)

/* Extract the wanted records from the temporary table */
SELECT[totalCount],
RecordsLeft =
(
SELECT COUNT(*)
FROM #TempTable TI
)
FROM#TempTable

SET NOCOUNT OFF

RETURN
;
GO



And then the following function which specifies the where clause of the statement


function getOrderCount(strDate, strStatusList)
getOrderCount = 0
dim objRS, objSP, strWhereClause

if isDate(strDate) and len(strStatusList) > 0 then
'# Filter on order status



'# Filter on date clause
strWhereClause = "(tblOrders.orderDate >= " & sqlServerDate(strDate) & ")"

'#GET order count
Set objSP = SQLGetProcedure("spGetOrderCount")
SQLSetProcedureParam objSP, "search", strWhereClause

Set objRS = SQLExecuteProcedure(objSP)

if not objRS.eof then
getOrderCount = objRS("totalCount")
end if

'# Free resources
deleteRecordset(objRS)
deleteObject(objSP)
end if

end function


When I do this together I get the following error on my ASP Page

Microsoft OLE DB Provider for SQL Server error '80040e14'

Line 1: Incorrect syntax near '.'.

/sigma_eircommobdispatch/server/database.asp, line 235

And the print out of the resulting string from the function is

(tblOrders.orderDate >= CONVERT(DATETIME, '2007-7-13', 102))


If i remove the Where clause the statement works fine..

Any ideas

View 1 Replies View Related

How To Call A Userdefined Function Within A Stored

Aug 27, 2007

Hello All,
How do i call a user defined function from within a stored procedure,
I have created a simple function which takes firstname and lastname as parameters and returns the concatenated name string.
That part works.


declare @fullname varchar(400)
@fullName=getFullName(@firstname,@lastname)


As always thanks for all your input

View 4 Replies View Related

Use Function From Asp File In Stored Procedure

Jul 23, 2005

Hello everybody,I have a file with several asp functions where some depend on others.Some of the functions I will need to transform a string value.How can I include these functions in a stored procedure? (in SqlServer 2000)Do I have to add all the functions as userdefined functions?Or is possible to reference the external file like include files inasp?Thank you for your help!Regards,Michael

View 3 Replies View Related

Query Function In Stored Proc... How To Do It??

May 10, 2007

how can i view all the records in my stored procedure???



how is the query function done??



for example i had my datagrid view... and of course a view button that will trigger a view action in able to view the entire records that i input....



i am not familiar with such things..



pls help me to figure this out..



thanks..



im just a begginer when it comes to this..



pls help me..



thanks..



View 1 Replies View Related

Stored Function Encryption And Decryption

Oct 30, 2007



I created stored function with encryption.
after i created i dont able to view the source code from system tables or any tool.
i have get back the original source code

note: i want to stored function not for stored procedure.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved