Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Need help conveting this from Mysql to SQL server Expand / Collapse
Author
Message
Posted Monday, December 17, 2012 7:20 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 6:24 PM
Points: 32, Visits: 123
Select * from openquery([connection],'
-- Forum Messages by User
use databasebname;
select u.name, convert_tz(from_unixtime(m.modificationDate/1000),'+00:00','-08:00') as TimePST, m.subject, m.body, m.messageID, f.forumID, f.name
from jiveMessage m inner join
jiveUser u on m.userID = u.userID inner join
jiveForum f on m.forumID = f.forumID
where from_unixtime(m.modificationDate/1000) > date_sub(now(), interval 1 week)
and u.name like 'Luke'
order by m.modificationDate desc ')

The error I am getting is:
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near '+'.

Any help would be awesome.
Post #1397502
Posted Tuesday, December 18, 2012 10:42 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 12:08 PM
Points: 4,238, Visits: 9,480
Single quotes within single quotes may be causing issues. Try this instead:

select *
from openquery([connection], '
-- Forum Messages by User
use databasebname;
select u.name, convert_tz(from_unixtime(m.modificationDate/1000),''+00:00'',''-08:00'') as TimePST, m.subject, m.body, m.messageID, f.forumID, f.name
from jiveMessage m inner join
jiveUser u on m.userID = u.userID inner join
jiveForum f on m.forumID = f.forumID
where from_unixtime(m.modificationDate/1000) > date_sub(now(), interval 1 week)
and u.name like ''Luke''
order by m.modificationDate desc ')



____________________________________________________________________________________________

Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:

http://www.sqlservercentral.com/articles/Best+Practices/61537/

If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
Post #1397924
Posted Tuesday, December 18, 2012 3:37 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 6:24 PM
Points: 32, Visits: 123
Perfect - now getting
Duplicate column names are not allowed in result sets obtained through OPENQUERY and OPENROWSET. The column name "name" is a duplicate.

Owh the joys of mySQL and MSSQL....

** No need for a reply to this just passing comment... ranting really.

Thanks for the help!
Post #1398078
Posted Wednesday, December 19, 2012 1:14 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 12:08 PM
Points: 4,238, Visits: 9,480
Brad Marsh (12/18/2012)
Perfect - now getting
Duplicate column names are not allowed in result sets obtained through OPENQUERY and OPENROWSET. The column name "name" is a duplicate.

Owh the joys of mySQL and MSSQL....

** No need for a reply to this just passing comment... ranting really.

Thanks for the help!


Presume you got this sorted via use of column aliases on the 'name' columns?


____________________________________________________________________________________________

Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:

http://www.sqlservercentral.com/articles/Best+Practices/61537/

If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
Post #1398223
Posted Wednesday, December 19, 2012 1:28 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 6:53 AM
Points: 1,227, Visits: 1,712
dont forget to use

dateadd(s, 875996580, '1/1/1970') for from_unixtime.

convert_tz function does not exist in sql server so best bet is using aux table or datetimeoffset datatype.


Alex S
Post #1398650
Posted Wednesday, December 19, 2012 1:53 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 6:24 PM
Points: 32, Visits: 123
Phil I used as xxx, that did the trick.


In relation to the convert, it actually did work. I thought this would work as my perception of running a linked server to MySQL still means I am making the query on MySQL directly.

My use case is j need to pull metrics and when I try and import the database into execl it crashes so I had to link the server and use SQL server to prevent a crash.
Post #1398657
Posted Wednesday, December 19, 2012 2:28 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 12:08 PM
Points: 4,238, Visits: 9,480

In relation to the convert, it actually did work. I thought this would work as my perception of running a linked server to MySQL still means I am making the query on MySQL directly.

Correct.


____________________________________________________________________________________________

Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:

http://www.sqlservercentral.com/articles/Best+Practices/61537/

If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
Post #1398673
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse