SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


insert and update issue


insert and update issue

Author
Message
jeff.jmathews
jeff.jmathews
SSC Rookie
SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)

Group: General Forum Members
Points: 38 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.
bitbucket-25253
bitbucket-25253
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26909 Visits: 25280
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
jeff.jmathews
jeff.jmathews
SSC Rookie
SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)

Group: General Forum Members
Points: 38 Visits: 20
ive checked and rechecked passed in values.

Im only passing in two ID's and four bit values from check boxes.
Artur Sokhikyan
Artur Sokhikyan
SSC-Addicted
SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)SSC-Addicted (462 reputation)

Group: General Forum Members
Points: 462 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...
Vijaya Kadiyala
Vijaya Kadiyala
SSCarpal Tunnel
SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)

Group: General Forum Members
Points: 4409 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



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search