Click here to Skip to main content
15,878,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

Can any one please suggest me how to convert the following mysql query to SQL Server?

SQL
read_loop: LOOP
  FETCH CUR1 INTO @patientId,@offerId,@touchpointId

  If @done THEN
  leave read_loop
  End
  select @tempCount=count(*) from  patient_offers where patient_patientId=@patientId and @offerId=offers_offerId and touchpoint_touchpointId=@touchpointId
 IF(@tempCount=0)

  insert into patient_offers(patient_patientId,offers_offerId,touchpoint_touchpointId,allocatedOn,allocatedBy,status,icode)

  values(@patientId,@offerId,@touchpointId,convert(nvarchar(20),getdate(),120),1,'1',1252)

 END
 END LOOP



Regards,
Nagaraj
Posted
Comments
Ed Nutting 20-Feb-12 13:27pm    
Just a suggestion but try searching Google for MySQL and SQL Server equivalents - you might find a site that lists the equivalent statements. Though so far as I was aware, SQL was a language in its own right regardless of database engine you are using so the code my not need changing much.
Bernhard Hiller 5-Mar-12 2:51am    
SQL means Structured Query Language, not Standard Query Language. There are some differences in the SQL between database engines.
Ed Nutting 5-Mar-12 3:00am    
Precisely...which is why I recommended finding a site that showed the differences between the different versions and what the equivalent terms are, if any. SQL structure does transfer between database systems and syntax remains fairly similar. It is a language in its own right, the same way you have MonoSharp a version of C# for linux and .Net C# they are pretty much the same and C# is still a language they just have minor differences in the final lines of code.
Bernhard Hiller 5-Mar-12 2:55am    
Though it's not the answer to your original problem, I'd like to suggest that you change the datatype of "allocatedOn" from char/varchar to DateTime, thus you'll not need to convert that type conversion either.
Also check if "status" really needs to be a char/varchar, it could be a numeric type.

1 solution

 
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