How can I get DISTINCT rows returned with this setup?
When I run my query like this I get DISTINCT rows.
SELECT DISTINCT t.tbt_no, t.country, t.date_issued, t.products, t.final_comment_date
FROM OPENDATASOURCE('SQL', 'Data Source=TSSQL;User Id=myid;Password=mypassword').mydb.dbo.thisdb t
WHERE EXISTS (SELECT COUNTRY_NAME FROM dbo.REGIONS WHERE REG_ID = 5 AND t.country = COUNTRY_NAME) AND (t.final_comment_date >= { fn NOW() })
ORDER BY t.tbt_no
I want to be able to display the results randomly so I tried adding the newID function and this inserts in all of the results as if the DISTINCT keyword was not there.
SELECT DISTINCT t.tbt_no, t.country, t.date_issued, t.products, t.final_comment_date, newID AS NUM
FROM OPENDATASOURCE('SQL', 'Data Source=TSSQL;User Id=myid;Password=mypassword').mydb.dbo.thisdb t
WHERE EXISTS (SELECT COUNTRY_NAME FROM dbo.REGIONS WHERE REG_ID = 5 AND t.country = COUNTRY_NAME) AND (t.final_comment_date >= { fn NOW() })
ORDER BY NUM
Thanks for your help.
When I run my query like this I get DISTINCT rows.
SELECT DISTINCT t.tbt_no, t.country, t.date_issued, t.products, t.final_comment_date
FROM OPENDATASOURCE('SQL', 'Data Source=TSSQL;User Id=myid;Password=mypassword').mydb.dbo.thisdb t
WHERE EXISTS (SELECT COUNTRY_NAME FROM dbo.REGIONS WHERE REG_ID = 5 AND t.country = COUNTRY_NAME) AND (t.final_comment_date >= { fn NOW() })
ORDER BY t.tbt_no
I want to be able to display the results randomly so I tried adding the newID function and this inserts in all of the results as if the DISTINCT keyword was not there.
SELECT DISTINCT t.tbt_no, t.country, t.date_issued, t.products, t.final_comment_date, newID AS NUM
FROM OPENDATASOURCE('SQL', 'Data Source=TSSQL;User Id=myid;Password=mypassword').mydb.dbo.thisdb t
WHERE EXISTS (SELECT COUNTRY_NAME FROM dbo.REGIONS WHERE REG_ID = 5 AND t.country = COUNTRY_NAME) AND (t.final_comment_date >= { fn NOW() })
ORDER BY NUM
Thanks for your help.