Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Following is My SQL server queries
SQL
select top 100 COUNT(distinct cast(ip as varchar) + cast(sessionid as varchar)) as ActiveUsr from tblTrackingRTT tr where tr.parent=@parent and
    tr.site=@site and tr.ms_date>=DATEADD(MINUTE, -5, getdate())


I converted this query to Mysql


SQL
select  COUNT(distinct cast(ip as varchar) + cast(sessionid as varchar(1))) as ActiveUsr from tblTrackingRTT tr where tr.parent=p_parent and
    tr.site=p_site and tr.ms_date>=TIMESTAMPADD(MINUTE, -5, now()) Limit 100;


its give me following error
"Select is not valid position for this server position excepting : ("

What I have tried:

everything i tried i didnt get it
Posted
Updated 4-Nov-19 1:55am
v2

1 solution

First of all, i'd start from counting the number of opening and closing parenthesis...

Second of all, i'd use CONCAT[^] function to return concatenated string and use proper data type:

Quote:
The target type can be any one of the following types: BINARY, CHAR, DATE, DATETIME, TIME, DECIMAL, SIGNED, UNSIGNED .


SQL
SELECT COUNT(distinct CONCAT(CAST(ip as char), CAST(sessionid as char))) AS ...
 
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