Need Help With Stored Proc. Pretty Simple For An Experienced Person
Sep 6, 2007
Can someone help me rewrite this query? Basically I need to check if the name stored in "CustomerName" already exist in the table "Renter". If it does not then I ncan insert the new customer name
into the data table "Renter". If the value in "CustomerName" already exists in the database, then I need to bypass the "INSERT" and somehow return a value indicating that the insert was not performed. How can I do this. Here is the
query I currently have for performing the insert.
CREATE PROCEDURE [dbo].[VacancyGet]
(
@CustomerName nvarchar(100),
@ClientCode nvarchar(10)
)
AS
INSERT INTO Renter
(
CustomerName,
ClientCode,
)
VALUES
(
@CustomerName,
@ClientCode,
)
View 1 Replies
ADVERTISEMENT
Oct 13, 2005
Hi,
I'm having problems with a stored procedure, that i'm hoping someone can help me with.
I have a table with 2 columns - Username (varchar), LastAllocation (datetime)
The Username column will always have values, LastAllocation may have NULL values. Example
Username | LastAllocation
------------------------
Greg | 02 October 2005 15:30
John | 02 October 2005 18:00
Mike | <NULL>
My stored procedure needs to pull back a user name with the following criteria:
If any <NULL> dates send username of first person where date is null, sorted alphabetically, otherwise send username of person with earliest date from LastAllocation
Then update the LastAllocation column with GETDate() for that username.
This SP will be called repeatedly, so all users will eventually have a date, then will be cycled through from earliest date. I wrote an SP to do this, but it seems to be killing my server - the sp works, but I then can't view the values in the table in Enterprise Manager. SP is below - can anyone see what could be causing the problem, or have a better soln?
Thanks
Greg
------------------------------------------------------------------------------
------------------------------------------------------------------------------
CREATE PROCEDURE STP_GetNextSalesPerson AS
DECLARE @NextSalesPerson varchar(100)
BEGIN TRAN
IF (SELECT COUNT(*) FROM REF_SalesTeam WHERE LeadLastAllocated IS NULL) > 0
BEGIN
SELECT TOP 1 @NextSalesPerson = eUserName FROM REF_SalesTeam WHERE LeadLastAllocated IS NULL ORDER BY eUserName ASC
END
ELSE
BEGIN
SELECT TOP 1 @NextSalesPerson = eUserName FROM REF_SalesTeam ORDER BY LeadLastAllocated ASC
END
SELECT @NextSalesPerson
UPDATE REF_SalesTeam SET LeadLastAllocated = GETDATE() WHERE eUserName = @NextSalesPerson
COMMIT TRAN
GO
View 2 Replies
View Related
May 7, 2008
Hello there, i'm pretty new to web development and i've come across this problem, so here's the case.I got a videoclub database and i wanna show the movies categorized by the category that the movie belongs to. I got a table with all the categories (the table includes an ID and the name of the category),and the movies table has movie data plus a category id field which is related with the categories table. Anyway enough with the background info here's the query i'm trying to use:SELECT MovieID, Name, Director, Category, Casting, Photo, Supplier, ReleaseDateFROM MoviesWHERE (Category = @ Category) The error i'm getting on the query builder is "Error in WHERE clause near '@'. Unable to parse query text.". If i aint wrong i'm supposed to use the "@" to indicate that its supposed to get data from a control. Anyway thats the prob, any help would be really apreciated.P.S. The control i'm using is a dropdownlist that shows the categories names and has as a value the category id, so there isn't a variable miss match error as much as i know.
View 15 Replies
View Related
Jul 27, 2006
I'm trying to do some basic stuff in SQL Server 2005 that I could do in Oracle. I'm sure there's a way to do these things, I just don't know how. My most immediate question is this:
Is there any easy way to run a SQL script and have it spool to HTML tables to a file? The 'results to text' from SSMS is not adequate for display purposes. I'm trying to display table/column descriptions.
Beyond that, does anyone know of any good resources that provide an 'Oracle to SQL Server' matrix so I can help figure out how to do some of these things in SQL Server?
Thanks in advance,
Mike
View 1 Replies
View Related
Sep 21, 2005
I have a stored procedure that looks like this-
IF NOT EXISTS
(Expression evaluates to true)
BEGIN
INSERT INTO Table
(Account, CustomerName )
VALUES
(@Account, @CustomerName)
SELECT Column FROM Table
WHERE PrimaryKey = PrimaryKeyJustCreatedAbove
END
I'm creating a new record in the table, after I create this record I want to select the columns from the newly created record. Problem is the only unique value is the primarykey that is created with the record. Is there a way to identify that value within the statement?
View 7 Replies
View Related
Oct 25, 2006
I want to test some times it takes for a proc to run. Since I work for a large company, I rarely have access to the SQL server in a capacity where I can use profiler and such. Are there any quick and easy ways to just surround blocks of code in a T-SQL statement to get an accurate reading on how long it takes?I.e., if I surround with GETDATE() before and after, does that also measure the round trips to the server, or just the execution time.I want to just compare some different methods and see what is quicker. THX.
View 4 Replies
View Related
Feb 13, 2008
I am working with a large application and am trying to track down a bug. I believe an error that occurs in the stored procedure isbubbling back up to the application and is causing the application not to run. Don't ask why, but we do not have some of the sourcecode that was used to build the application, so I am not able to trace into the code.
So basically I want to examine the stored procedure. If I run the stored procedure through Query Analyzer, I get the following error message:
Msg 2758, Level 16, State 1, Procedure GetPortalSettings, Line 74RAISERROR could not locate entry for error 60002 in sysmessages.
(1 row(s) affected)
(1 row(s) affected)
I don't know if the error message is sufficient enough to cause the application from not running? Does anyone know? If the RAISERROR occursmdiway through the stored procedure, does the stored procedure terminate execution?
Also, Is there a way to trace into a stored procedure through Query Analyzer?
-------------------------------------------As a side note, below is a small portion of my stored proc where the error is being raised:
SELECT @PortalPermissionValue = isnull(max(PermissionValue),0)FROM Permission, PermissionType, #GroupsWHERE Permission.ResourceId = @PortalIdAND Permission.PartyId = #Groups.PartyIdAND Permission.PermissionTypeId = PermissionType.PermissionTypeId
IF @PortalPermissionValue = 0BEGIN RAISERROR (60002, 16, 1) return -3END
View 3 Replies
View Related
Apr 12, 2007
How do I add a previously-made SQL Compact Edition database to my Visual Basic.Net 2005 project inside Visual Studio, and ensure that it gets built into the ClickOnce-deployed solution? Our dba has completed the db design for our project, and I need to add the file to the project I am writing business logic for.
View 5 Replies
View Related
Feb 3, 2006
hey guys very new to sql server - i can take care of the basic CRUD but,i'm not familiar with some of the syntax to handle stuff right in the proc. i've been making multiple round trips to accomplish what i think i should be able to do based on a condition right when im in the procedure itself. so, please bear with me.
i have a table with these 5 fields.
"AltNumb" "AltName" "TimeLastRun" "TimeNextRun" "skdDuration"
ALT001 FIRST ALERT 2/2/2006 12:42:00 PM 2/2/2006 2:35:00 PM 5
ALT002 SECOND ALERT 2/2/2006 12:42:00 PM 2/2/2006 2:43:00 PM 10
ALT003 SECOND ALERT 2/2/2006 12:42:00 PM 2/2/2006 2:48:00 PM 15
i have a service that will call a procedure that takes the current_timestamp and compares it (datediff) with the column "TimeLastRun" and see's if it's equal with the "SkdDuration" - some are set to 5, 10, 15 minutess etc.
heres's the short lil proc below:
CREATE PROCEDURE dbo.Check_Time_Duration
AS
declare @myDate smalldatetime
select @myDate = getdate()
SELECT AlertNumber from time_check2 where DATEDIFF(MINUTE,timeLastRun,@myDate) = Schedule_Duration
what i'd like to do is if anything matches, is Update the two columns "TimeLastRun" & "TimeNextRun" right on the spot based on the AlertNumber(if that row matches in the above query).
something like this:
DECLARE @myDate smalldatetime
select @myDate = getDate()
Update time_check2 set timelastrun=@myDate,timenextrun=dateadd(minute,5,@ myDate)where AlertNumber ='ALT001'--this would need to be a variable
BUT the AlertNumber of course matched in the first select
Hopefully someone can see what i'm trying to accomplish here and give me some help
Been on Oracle too long - i feel like a real newbie here
thanks again
rik
View 1 Replies
View Related
Aug 24, 2006
I am having trouble executing a stored procedure on a remote server. On my
local server, I have a linked server setup as follows:
Server1.abcd.myserver.comSQLServer2005,1563
This works fine on my local server:
Select * From [Server1.abcd.myserver.comSQLServer2005,1563].DatabaseName.dbo.TableName
This does not work (Attempting to execute a remote stored proc named 'Data_Add':
Exec [Server1.abcd.myserver.comSQLServer2005,1563].DatabaseName.Data_Add 1,'Hello Moto'
When I attempt to run the above, I get the following error:
Could not locate entry in sysdatabases for database 'Server1.abcd.myserver.comSQLServer2005,1563'.
No entry found with that name. Make sure that the name is entered correctly.
Could anyone shed some light on what I need to do to get this to work?
Thanks - Amos.
View 3 Replies
View Related
Jun 15, 2006
Hi All,Quick question, I have always heard it best practice to check for exist, ifso, drop, then create the proc. I just wanted to know why that's a bestpractice. I am trying to put that theory in place at my work, but they areasking for a good reason to do this before actually implementing. All Icould think of was that so when you're creating a proc you won't get anerror if the procedure already exists, but doesn't it also have to do withCompilation and perhaps Execution. Does anyone have a good argument fordoing stored procs this way? All feedback is appreciated.TIA,~CK
View 3 Replies
View Related
Feb 23, 2007
I have an ASP that has been working fine for several months, but itsuddenly broke. I wonder if windows update has installed some securitypatch that is causing it.The problem is that I am calling a stored procedure via an ASP(classic, not .NET) , but nothing happens. The procedure doesn't work,and I don't get any error messages.I've tried dropping and re-creating the user and permissions, to noavail. If it was a permissions problem, there would be an errormessage. I trace the calls in Profiler, and it has no complaints. Thedatabase is getting the stored proc call.I finally got it to work again, but this is not a viable solution forour production environment:1. response.write the SQL call to the stored procedure from the ASPand copy the text to the clipboard.2. log in to QueryAnalyzer using the same user as used by the ASP.3. paste and run the SQL call to the stored proc in query analyzer.After I have done this, it not only works in Query Analyzer, but thenthe ASP works too. It continues to work, even after I reboot themachine. This is truly bizzare and has us stumped. My hunch is thatwindows update installed something that has created this issue, but Ihave not been able to track it down.
View 1 Replies
View Related
Feb 20, 2003
I have seen this done by viewing code done by a SQL expert and would like to learn this myself. Does anyone have any examples that might help.
I guess I should state my question to the forum !
Is there a way to call a stored proc from within another stored proc?
Thanks In Advance.
Tony
View 1 Replies
View Related
Jan 13, 2006
Hi all,
I have a stored procedure "uspX" that calls another stored procedure "uspY" and I need to retrieve the return value from uspY and use it within uspX. Does anyone know the syntax for this?
Thanks for your help!
Cat
View 5 Replies
View Related
Jan 20, 2004
Hi all
I have about 5 stored procedures that, among other things, execute exactly the same SELECT statement
Instead of copying the SELECT statement 5 times, I'd like each stored proc to call a single stored proc that executes the SELECT statement and returns the resultset to the calling stored proc
The SELECT statement in question retrieves a single row from a table containing 10 columns.
Is there a way for a stored proc to call another stored proc and gain access to the resultset of the called stored proc?
I know about stored proc return values and about output parameters, but I think I am looking for something different.
Thanks
View 14 Replies
View Related
Aug 30, 2007
I would like to know if the following is possible/permissible:
myCLRstoredproc (or some C# stored proc)
{
//call some T SQL stored procedure spSQL and get the result set here to work with
INSERT INTO #tmpCLR EXECUTE spSQL
}
spSQL
(
INSERT INTO #tmpABC EXECUTE spSQL2
)
spSQL2
(
// some other t-sql stored proc
)
Can we do that? I know that doing this in SQL server would throw (nested EXECUTE not allowed). I dont want to go re-writing the spSQL in C# again, I just want to get whatever spSQL returns and then work with the result set to do row-level computations, thereby avoiding to use cursors in spSQL.
View 2 Replies
View Related
May 24, 2007
Hey guys, I'm new to reporting services and I just need to throw together a report that references multiple datasources. I can query up all my info individually, but I need to write a query that says,
Select ProductName,ProductId from datasource 2
where ProductId = @ProductIdFromDataSource1
I can get this to work, but if my query from datasource 1 returns 10 productID's, this will only return the productname from the first ProductID, 10 times. I believe that's because I'm using the First() aggregate function. Is there another function I can use that doesn't do that, or some way I can reference each field individually?
Just to clarify a little more, here's what I want:
Code Snippet
Product ID (ds 1) ProductName (ds 2)
------------------------ ----------------------
11 A
12 B
13 C
123 D
and here's what I'm getting right now:
Code Snippet
Product ID (ds 1) ProductName (ds 2)
------------------------ ----------------------
11 A
12 A
13 A
123 A
Thanks!
View 4 Replies
View Related
Dec 5, 2007
Good Morning,
Hate to sound so dumb, but, it's been years since I've done any SQL programming and I was bad at the time!
What is the code for taking my time stamp 2007-02-09 10:15:02.000 and just displaying the date as 02/09/2007?
Do I use variables? Are they set up before my select statement? Can anyone suggest a really good, easy, very explanable SQL (that will work in SQL Server) progamming book?
Thanks so much!
Dianne
View 5 Replies
View Related
Jun 30, 2000
Hi,
I changed the sa password today on my subscriber databases, and now my transactional replication fails, as it cannot connect to the subscribers. I updated the publisher's linked server logins, but it still fails. Help please!
Thanks,
Jason
View 2 Replies
View Related
Oct 4, 2000
Hi,
I am getting many instances of the following error, and I cannot find any documention on it, or how to remedy. Any help/suggestions would be GREATLY appreciated.
Thanks in advance - jason
SQL Server Assertion: File: <xcbmgr.cpp>, line=1299
Failed Assertion = 'pss->IsXcbLocked ()'.
Dump thread - spid = 58, PSS = 0x2e637158, EC = 0x2e637308
Stack Dump being sent to C:MSSQL7logSQL00115.dmp
************************************************** *****************************
*
* BEGIN STACK DUMP:
* 10/04/00 16:39:54 spid 58
*
* Input Buffer 42 bytes -
* s e l e c t u i d = N E W I D ( )
*
************************************************** *****************************
View 1 Replies
View Related
Aug 17, 2007
I know that the query governor works off of estimated query plans, but the estimation is usually so far off from reality that it might as be generating a random number to determine whether a query should run.
Right now I have query governor set at 300. I've been able to run queries that take more than 10 minutes without any complaint from query governor.
What's really annoying though, is that it has also blocked queries that take less than a second to run. It blocked a query for having an estimated executing time of 338 seconds. When I set the limit up to 400, the query ran virtually instantly.
Is this just how query governor is suppose to work? Is there any way to make it work better?
View 3 Replies
View Related
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
Apr 23, 2008
Hello friends......How are you ? I want to ask you all that how can I do the following ?
I want to now that how many ways are there to do this ?
How can I call one or more stored procedures into perticular one Stored Proc ? in MS SQL Server 2000/05.
View 1 Replies
View Related
Dec 18, 2007
Hi Peeps
I have a SP that returns xml
I have writen another stored proc in which I want to do something like this:Select FieldOne, FieldTwo, ( exec sp_that_returns_xml ( @a, @b) ), FieldThree from TableName
But it seems that I cant call the proc from within a select.
I have also tried
declare @v xml
set @v = exec sp_that_returns_xml ( @a, @b)
But this again doesn't work
I have tried changing the statements syntax i.e. brackets and no brackets etc...,
The only way Ive got it to work is to create a temp table, insert the result from the xml proc into it and then set @v as a select from the temp table -
Which to be frank is god awful way to do it.
Any and all help appreciated.
Kal
View 3 Replies
View Related
Dec 26, 2006
I am quite newbie, really grateful for some help how to create a sql sentence in Reporting Services that would return the best sales person from each shop.. The following returns all the sales persons from each shop
So how to select the top sales person from each shop?
SELECT TOP (10) shop.name, SUM(Cd.Price) AS Sales, Personal.Name AS Salesperson
FROM Purchase INNER JOIN
Personal
ON Purchase.Salesperson_id = Personal.Personal_id RIGHT OUTER JOIN shop
ON Personal.work_id = shop.shop_id FULL OUTER JOIN
Cd ON Purchase.Cd_id = Cd.Cd_id
GROUP BY Shop.Name, Personal.Name
ORDER BY Sales DESC
Or something like this? But how in Rep.Services???
...LEFT OUTER JOIN (
SELECT P.work_id, P.Name, SUM(C.Price) AS TotalSale
FROM @Personal P
INNER JOIN @Purchase B
ON B.Salesperson_id = P.Personal_id
INNER JOIN @Cd C
ON C.Cd_id = B.Cd_id
GROUP BY P.Work_id, P.Name
) D
ON D.Work_id = S.Shop_id
View 4 Replies
View Related
Oct 15, 2007
I can believe it, 40 people read my sql query problem and ONLY ONE reply to my request for help.
Thanks!!!! It's great to know that we help each other in this community.
View 1 Replies
View Related
Dec 6, 2005
We're developing an application request/packaging/rollout worflowapplication for our 50 site, 40,000 user company. There is a requesttable, an engineering table, a distribution table, etc. etc. But, thecompany has a designated "Application Owner" at each site, and eachperson who will use the application must also be listed in the workflowapplication. So, we need a lookup table for the owners and users:CREATE TABLE REQUEST (RQ_ID INTEGER NOT NULL,RQ_BY_ID INTEGER NOT NULL,RQ_FOR_ID INTEGER NOT NULL,ASSIGNED_ENGINEER_ID INTEGER NOT NULL,OTHER INFO...);CREATE TABLE APP_OWNERS (RQ_ID INTEGER NOT NULL,OWNER_ID INTEGER NOT NULL);CREATE TABLE APP_USERS (RQ_ID INTEGER NOT NULL,USER_ID INTEGER NOT NULL);There are many other tables, of course, some with single person IDfields and addititional lookup tables where there are multiple peopleinvolved like testers, package distributors, etc. I began to wonder,why not just a single table to cover ALL the people involved:CREATE TABLE RQ_WORKFLOW_PEOPLE (RQ_ID INTEGER NOT NULL,PERSON_ROLE VARCHAR(20) NOT NULL,PERSON_ID INTEGER NOT NULL);INSERT INTO RQ_WORKFLOW_PEOPLE (rq_id,person_role,person_id) values(123456,'RQ BY',314159),(123456,'RQ FOR',951413),(123456,'APP OWNER',159413),(123456,'APP OWNER',413159),(123456,'USER',594131),(123456,'USER',313459),.....The real question I have is how does one evaluate options like this?The good news, I think, is that where I simply must have crossreference tables because of multiple values (application owners, users,testers, etc.) I've reduced the number of those tables to one byspecifying a single table by role. Is that a good thing or a bad thing?I've also removed similar data from several other tables where only asingle column was needed in those tables, i.e. the requested by andrequested for fields, the assigned engineer, and several others. Thereis one and only one of each for each request but the type of data, thatis an employee ID is exactly the same, so does it make more "sense" tokeep the data with the request table or the engineering table orconsolidate all ID data in an ID table?Any thoughts on this woudl be appreciated.Randy
View 2 Replies
View Related
Apr 4, 2008
I am gonig into interview for a junior developer position. The role involves a lot of SQL based work. Training is on the job, and they know I am new to this, but they want to know what I can do with SQL server by wednesday, and obviosuly I stand a better chance if I can do a reasonable amount by then.I am assuming I can practise with offline databases, so I would like to do that. Also I was wondering if there were any simple example databases I can load up.
I have downloaded and installed the software, and would like to know how to connect and create a test database.
There will be a small test in the interview and the questions are:
1. SQL Management and Data Extraction
For this task you will need to be familiar with database tables, data types and constraints. There will be some administration work using SQL Management Studio along with some T-SQL queries. You will need to show use of the SELECT, INSERT, UPDATE and DELETE statements. If you do not have SQL Server, you can download the express edition for free at the following URL. http://msdn2.microsoft.com/en-us/express/bb410791.aspx
2. XSLT
For this task I will be asking you to produce some HTML output displaying the data from an XML file. The concept is similar to ASP.
3. Database Design
You will be given a scenario for a company that requires some database software for the smooth running of their organisation. You will need to plan and design a data structure to accommodate these requirements. You will be allowed to spend as much time on this part of the test as you wish. Key information here is going to be database normalization.
These questions dont make a whole lot of sense to be at the moment, so would appreciate a breakdown in simpler terms.
This job will be a fantastic opportunity for me to get into development, and would appreaciate any help that you guys have to offer, thanks in advance.
View 21 Replies
View Related
Jan 17, 2008
Hi
In a transactions table, I need to get the record for the earliest transaction date for each person or account. So far I've been doing it in 2 steps (below). Is there an easier way to do this?
Thanks
Dannie
--------------------------
SELECT
Person_ID
Earliest_Transaction_Date = MIN( Transaction_Date )
INTO
Earliest_Transaction_Dates
FROM
All_Transactions
GROUP BY
Person_ID
SELECT
b.*
FROM
Earliest_Transaction_Dates a
LEFT OUTER JOIN
All_Transactions b
WHERE
a.Person_ID = b.Person_ID
and b.Transaction_Date = a.Earliest_Transaction_Date
View 3 Replies
View Related
Dec 21, 2006
I'm fairly new to RS and have a problem.
I have a query that pulls information on people, courses they have taken, their score and so on. I have a date parameter setup so I can run it by year. Everything works ok on the query side, I get all the information I need on all the people and the courses they have taken. However, when I run the report, I do not get a separate page for each person and their relative information. The first page shows the first name and the rest of the 700 pages list all the courses and other information, with no break. How do I render the report so that I can get a separate page(s) for each person and their specific info? I can glady provide more info/code if need be.
Bill
View 8 Replies
View Related
Feb 14, 2007
I have about 8 databases to integrate. All of the databases have ssno, address city...ect. I need to create a DW table with one unique record for each actual person. In other words,
Joe Smith,123 Main St, Anytown, State,....+ssno
goes into the DW table and is the same person as Joseph S. Smith,123 Main Street... and any other versions.
Could someone point me to a reference or give me an outline of how to do this in and SSIS package?
Is fuzzy logic used here?
Do I need to deduplicate the feeder systems first??
It needs to handle a situation in, for example, the Bronx New York where there could be an apartment buiding with 7 people named Jose Sanchez .
I hope I've been clear, I'm a newbie at this DW stuff, but it's fascinating. Any help would be appreciated. Thanks
View 1 Replies
View Related
Aug 23, 2007
When you create a Stored procedure, is it automatically stored under the default Filegoup?
How can I see under which Filegroup my Stored Procedures and Triggers are stored?
View 2 Replies
View Related
Mar 10, 2005
I didn't want to maintain similar/identical tables in a legacy FoxPro system and another system with SQL Server back end. Both systems are active, but some tables are shared.
Initially I was going to use a Linked Server to the FoxPro to pull the FP data when needed. This works. But, I've come up with what I believe is a better solution. Keep in mind that these tables are largely static - occassional changes, edits.
I will do a 1 time DTS from FP into SQL Server tables.
I then create INSERT and UPDATE triggers within FoxPro.
These triggers fire a stored procedure in FoxPro that establishes a connection to the SQL Server and fire the appropriate stored procedure on SQL Server to CREATE and/or UPDATE the corresponding table there.
In the end - the tables are local to both apps.
If the UPDATES or TRIGGERS fail I write to an error log - and in that rare case - I can manually fix. I could set it up to email me from within FoxPro as well if needed.
Here's the FoxPro and SQL Server code for reference for the Record Insert:
FOXPRO employee.dbf InsertTrigger:
employee_insert_trigger(VAL(Employee.ep_pk),Employ ee.fname,Employee.lname,Employee.email,Employee.us er_login,Employee.phone)
FOXPRO corresponding Stored Procedure:
FUNCTION EMPLOYEE_INSERT_TRIGGER
PARAMETERS wepk,wefname,welname,weemail,WEUSERID,WEPHONE
nhandle=SQLCONNECT('SS_PDITHP3','userid','password ')
IF nhandle<0
m.errclose=.f.
IF !USED("errorlog")
USE tisdata!errorlog IN SELECT(1)
m.errclose=.t.
ENDIF
SELECT errorlog
INSERT INTO errorlog (date, time, program,source,user) ;
values (DATE(), TIME(), 'EMPLOYEE_INSERT_TRIGGER','nhandle<0 PARAMS: '+STR(wepk)+wefname+welname+weemail+WEUSERID+WEPHO NE,GETENV("username"))
IF m.errclose
USE IN errorlog
ENDIF
RETURN
ENDIF
nquery="exec ewo_sp_insertNewEmployee @WEPK ="+STR(wepk)+",@WEFNAME ='"+wefname+"',@WELNAME ='"+welname+"',@WEEMAIL ='"+weemail+"',@WEUSERID ='"+weuserid+"',@WEPHONE='"+wephone+"',@RETCODE =0"
nsucc=SQLEXEC(nhandle,nquery)
SQLDISCONNECT(nhandle)
IF nSucc<0
m.errclose=.f.
IF !USED("errorlog")
USE tisdata!errorlog IN SELECT(1)
m.errclose=.t.
ENDIF
SELECT errorlog
INSERT INTO errorlog (date, time, program,source,user) ;
values (DATE(), TIME(), 'EMPLOYEE_INSERT_TRIGGER','nSucc<0 PARAMS: '+STR(wepk)+wefname+welname+weemail+WEUSERID+WEPHO NE,GETENV("username"))
IF m.errclose
USE IN errorlog
ENDIF
ENDIF
RETURN
SQL SERVER Stored Procedure called from FOXPRO Stored Procedure
CREATE procedure ewo_sp_insertNewEmployee (
@WEPK int,
@WEFNAME char(20),
@WELNAME char(20),
@WEEMAIL char(50),
@WEUSERID char(15),
@WEPHONE char(25),
@RETCODE int OUTPUT
)
AS
insert into WO_EMP (
WE_PK,
WE_FNAME,
WE_LNAME,
WE_EMAIL,
WE_USERID,
WE_PHONE
)
VALUES (
@WEPK,
@WEFNAME,
@WELNAME,
@WEEMAIL,
@WEUSERID,
@WEPHONE
)
IF @@ERROR <> 0
BEGIN
SET @RETCODE=@@ERROR
END
ELSE
BEGIN
-- SUCCESS!!
SET @RETCODE=0
END
return @RETCODE
GO
View 2 Replies
View Related