Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
code:-
use MYSQL;
Declare @Max_Id numeric
set @Max_Id=convert(numeric,(select max(id) from traffic));
insert into MYSQL.dbo.traffic(id,date,time,ip,resultCode,bytes,url,authuser,sitesID,usersID)
select id,date,time,ip,resultCode,bytes,url,authuser,sitesID,usersID
From openquery(MYSQL,'select id,date,time,ip,resultCode,bytes,url,authuser,sitesID,usersID from myvar.traffic where id > ''+@Max_Id+'''')


@Max_Id is acting as a string but it is a variable.i declare it as variable how can i give the variable in the above statement
Posted
Updated 5-Aug-13 0:50am
v4
Comments
TrushnaK 5-Aug-13 5:53am    
why you appending + to @Max_Id..
kalisiddayya 5-Aug-13 5:58am    
i want to run the query for one hour.i dont want the old record to store in the table again

There is a issue with your query. Try the modified query.

SQL
use MYSQL;
Declare @Max_Id Integer
set @Max_Id=(select max(id) from traffic);
insert into MYSQL.dbo.traffic(id,date,time,ip,resultCode,bytes,url,authuser,sitesID,usersID)
select id,date,time,ip,resultCode,bytes,url,authuser,sitesID,usersID
From openquery(MYSQL,'select id,date,time,ip,resultCode,bytes,url,authuser,sitesID,usersID from myvar.traffic where id > ''+@Max_Id+'''')
 
Share this answer
 
Comments
kalisiddayya 5-Aug-13 5:55am    
is it single quotes or double quotes at MaxId? near MAXID some Quotation are wrong
ArunRajendra 5-Aug-13 5:58am    
Single quote
kalisiddayya 5-Aug-13 6:20am    
column name datatype is numeric.when i compare the condition is not working i am getting all the values from the table
kalisiddayya 5-Aug-13 6:48am    
Max_ID is accepting as string .not as a variable.
ArunRajendra 5-Aug-13 7:42am    
you can remove the single quotes.
By using inner join the problem can be solved .this works....

SQL
insert into MYSQL.dbo.traffic(id,date,time,ip,resultCode,bytes,url,authuser,sitesID,usersId)
SELECT t1.id,t1.date,t1.time,t1.ip,t1.resultCode,t1.bytes,t1.url,t1.authuser,t1.sitesID,t1.usersID FROM
   OPENQUERY(MYSQL, 'SELECT * FROM mysar.traffic') T1
   INNER JOIN
   MYSQL.DBO.traffic T2 ON T1.id > T2.id
 
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