SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Need help conveting this from Mysql to SQL server


Need help conveting this from Mysql to SQL server

Author
Message
Brad Marsh
Brad Marsh
SSC Rookie
SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)

Group: General Forum Members
Points: 40 Visits: 132
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.
Phil Parkin
Phil Parkin
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25476 Visits: 20662
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.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Brad Marsh
Brad Marsh
SSC Rookie
SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)

Group: General Forum Members
Points: 40 Visits: 132
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!
Phil Parkin
Phil Parkin
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25476 Visits: 20662
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.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
AlexSQLForums
AlexSQLForums
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2148 Visits: 2275
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
Brad Marsh
Brad Marsh
SSC Rookie
SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)

Group: General Forum Members
Points: 40 Visits: 132
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.
Phil Parkin
Phil Parkin
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25476 Visits: 20662

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.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search