Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here i have 2 tables
SQL
latlongtransactions
(
devId, 
lat, 
lon
) 

and 

devicemaster
(
devId, 
password
) 


Now my task is i have to insert lat and lon value in the latlongtransactions table by matching the devId with devicemaster table where password and devId is being checked inputted by the user.

Say for example, i am giving
12345 as devId,
9999 as password ,
lat as 10.2 and
lon as 10.9 as inputs

Now the task is lat and lon will be inserted into latlongtransactions table with the mentioned devId but firstly it will check the devId and password from devicemaster table.(here in devicemaster table devId is the primary key and a foreign key to the another table.)

Waitng for your reply.
Posted
Updated 8-Oct-15 20:13pm
v2

Hi,

Check this...

SQL
Create Procedure Insertvalues
(
@pa_devId int,--or as per your datatype
@pa_pass varchar(100),--or as per your datatype
@pa_lat decimal(10,2),--or as per your datatype
@pa_lon decimal(10,2),--or as per your datatype
@OutPutMess varchar(20)--or as per your requirement
)
As
Begin

Set @OutPutMess=''

Declare @cnt int

Set @cnt=0

Select @cnt = Count(*) from devicemaster where devId=@pa_devId and password=@pa_pass

if @cnt > 0 
Begin

insert into latlongtransactions (devId, lat, lon)  
values (@pa_devId,@pa_lat,@pa_lon)

Set @OutPutMess='Done'--or as per your requirement

end
else
Begin

Set @OutPutMess='Error'--or as per your requirement

End

Select @OutPutMess

End


Hope this will help you.

Cheers
 
Share this answer
 
v2
SQL
INSERT INTO latlongtransactions(devId, lat, lon)
    SELECT 12345 , 10.2, 10.9
        FROM dual
        WHERE EXISTS (SELECT * FROM devicemaster
                             WHERE devId = 12345
                               AND password = 9999 )
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900