Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

insert and update issue Expand / Collapse
Author
Message
Posted Tuesday, April 7, 2009 3:11 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, April 21, 2010 8:09 AM
Points: 2, Visits: 20
Hello all,

Im experiencing something I have never had an issue with.

I have a general insert update method. Below is a quick example of the code statements I am trying to execute.

DECLARE @EXISTS

a select statement that sets @EXISTS

IF @EXISTS = 1
BEGIN
UPDATE METHOD HERE
END

IF @EXISTS =0
BEGIN
INSERT METHOD HERE
END

Im not exactly sure what is happening, but I know the statements are being hit. I put a SELECT 1 in the @EXISTS =1 method and a SELECT 0 in the @EXISTS = 0 method.

I get the proper value back when I executescalar. 1 for update and 0 for insert.

Im at a complete loss here. If I execute the proc in management studio and pass in the exact same values, it runs fine and does exactly as it should. However, it runs from my aspx page and does nothing. Doesnt throw any errors.

Any help would be appreciated.
Post #692553
Posted Tuesday, April 7, 2009 3:24 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 8:45 PM
Points: 5,551, Visits: 24,425
Are you sure you are passing in a value - paraphrasing your procedure
CREATE PROC dbo.myproc
@Exists INT
AS
IF @EXISTS = 1
BEGIN
PRINT 'UPDATE METHOD HERE'
END

IF @EXISTS =0
BEGIN
PRINT 'INSERT METHOD HERE'
END

dbo.myproc NULL -- imitating passing of a NULL value ... nothing will happen and no error will be reported.


If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Post #692565
Posted Tuesday, April 7, 2009 3:28 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, April 21, 2010 8:09 AM
Points: 2, Visits: 20
ive checked and rechecked passed in values.

Im only passing in two ID's and four bit values from check boxes.
Post #692567
Posted Wednesday, April 8, 2009 6:45 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, March 27, 2013 1:25 AM
Points: 152, Visits: 96
Use Sql Server Profiler and look what statement exactly passed to server to run.

If it wouldn't help, write here your stored procedure and the statement from Sql Server Profiler.


-------------------------
- Name?
- Abu Dalah Sarafi.
- Sex?
- 3 times a week!
- No, no. Male or Female?
- Male, female, sometimes camel...
Post #693021
Posted Wednesday, April 8, 2009 8:19 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, October 25, 2010 6:09 AM
Points: 1,621, Visits: 409
Hi

Try using OUTPUT keyword to find out whther its updating any records or not.
CREATE TABLE EMPLOYEE_WORKING_HRS(
EMP_ID int NULL,
ENAME varchar(30) NULL,
YR varchar(4) NULL,
MON varchar(3) NULL,
WORKING_HRS int NULL,
RATE int NULL,
SALARY AS (WORKING_HRS*RATE)
)

INSERT INTO EMPLOYEE_WORKING_HRS VALUES(100,'SAM',2009,'JAN',176,100);
INSERT INTO EMPLOYEE_WORKING_HRS VALUES (101,'LIMO',2009,'JAN',176,110);
INSERT INTO EMPLOYEE_WORKING_HRS VALUES(102,'NAT',2009,'JAN',176,120);
INSERT INTO EMPLOYEE_WORKING_HRS VALUES (103,'BECK',2009,'JAN',176,130);

declare @Emp_ids table(ID int)
update EMPLOYEE_WORKING_HRS set RATE = RATE - 20
output inserted.EMP_ID into @Emp_ids
from EMPLOYEE_WORKING_HRS
WHERE RATE > 100
SELECT * FROM @Emp_ids

Modify the above code and see if your UPDATE statement is having any problems!!


Thanks -- Vijaya Kadiyala
www.dotnetvj.com
SQL Server Articles For Beginers



Post #693154
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse