Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 help me

Author  Topic 

vedjha
Posting Yak Master

228 Posts

Posted - 2008-09-29 : 00:44:44
declare @name varchar(500)
declare @ids varchar(20)
set @ids='U100000000'
begin tran
select @name=vastname from login where aid = @ids
if @name is not null
begin
update request123
set vasname=@name where vAsid=@ids
print @name
commit tran


end

else
begin
print 'Invalid ID'
rollback tran
end



How to know Update Command is Complete
it gives a number , how to store these numbers
as
0-commit Tran
1-Rollback Tran
I m not sure ...


Ved Prakash Jha

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-29 : 01:16:39
can you elaborate on what you want? are you trying to return status for update operation?
Go to Top of Page

vedjha
Posting Yak Master

228 Posts

Posted - 2008-09-29 : 02:18:01
I have to write ID one time if it is true than it will update the table
it gives me output as:

(0 row(s) affected)

ABC

then plz tell me how I know that Update is successfully or not


Ved Prakash Jha
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-29 : 02:32:53
quote:
Originally posted by vedjha

I have to write ID one time if it is true than it will update the table
it gives me output as:

(0 row(s) affected)

ABC

then plz tell me how I know that Update is successfully or not


Ved Prakash Jha


what does this return?

select vastname from login where aid ='U100000000'

Go to Top of Page

vedjha
Posting Yak Master

228 Posts

Posted - 2008-09-29 : 02:47:15
select vastname from login where aid ='U100000000'
it returns name of ID
as


ABC

as it returns ABC then it is to be updated in the another table.

Ved Prakash Jha
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-29 : 02:50:22
and what does this return?
select * from request123 where vasname='ABC' and vAsid='U100000000'

Go to Top of Page

vedjha
Posting Yak Master

228 Posts

Posted - 2008-09-29 : 04:31:16
It will return only one row with whole info

Ved Prakash Jha
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-29 : 04:44:28
quote:
Originally posted by vedjha

It will return only one row with whole info

Ved Prakash Jha


do you have any audit columns like datemodified,datecreated etc?
Go to Top of Page

vedjha
Posting Yak Master

228 Posts

Posted - 2008-09-29 : 04:54:12
no
columns as:
serial,vasid,vasname,vPackage,inoOfSpon,cStatus
in request123




Ved Prakash Jha
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-29 : 04:56:34
quote:
Originally posted by vedjha

no
columns as:
serial,vasid,vasname,vPackage,inoOfSpon,cStatus
in request123




Ved Prakash Jha


anyways if earlier query returned you data then that means you've row existing with updated values. which means update has happened successfully provided you didnt had value ABC in table before.
Go to Top of Page

vedjha
Posting Yak Master

228 Posts

Posted - 2008-09-29 : 04:59:49
no actually I have data in login table
form there i want retrieve data and update to table request123

Ved Prakash Jha
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-29 : 05:27:08
quote:
Originally posted by vedjha

no actually I have data in login table
form there i want retrieve data and update to table request123

Ved Prakash Jha


yup but what we queried now was in request123 which showed data is there meaning update was successful.
Go to Top of Page

vedjha
Posting Yak Master

228 Posts

Posted - 2008-09-29 : 05:40:59
sorry..... ID takes spaces by which Table does not updated

Ved Prakash Jha
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-29 : 05:46:35
quote:
Originally posted by vedjha

sorry..... ID takes spaces by which Table does not updated

Ved Prakash Jha


sorry didnt get what you're telling about. alternatively you can do following also

declare @name varchar(500)
declare @ids varchar(20)
set @ids='U100000000'

select @name=vastname from login where aid = @ids

update request123
set vasname=@name where vAsid=@ids

select @@rowcount as 'rows updated'
Go to Top of Page

vedjha
Posting Yak Master

228 Posts

Posted - 2008-09-29 : 06:43:15
Thank u

Ved Prakash Jha
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-29 : 06:48:28
welcome
Go to Top of Page
   

- Advertisement -