3

I'm having an issue with viewing data in QGIS 2 based on a spatial query in SQL Server 2008 R2.

The data appears to load, polygons appear and I can add thematic shading based on data.

However when I view the attribute table for the layer in QGIS, it seems like the same value is being replicated over and over again.

QGIS Data Screengrab

If I add labels, only one label appears despite there being multiple features with different attributes in the original SQL Spatial query.

QGIS Labels Screengrab

When I export the layer to a shapefile and open it in QGIS, all the data appears correctly and labelling works without any problem.

enter image description here

Why is the layer imported from SQL Server behaving so strangely?

1 Answer 1

4

QGIS must have a unique key column in order to track features. If you are missing that you will get this behavior.

You can do something like this for your view:

SELECT ROW_NUMBER() OVER(ORDER BY SalesYTD DESC) AS Row, MS0A01CD, count 
2
  • Ah thanks! The MSOA01CD field is unique but I see that the key must be numeric.
    – Tumbledown
    Commented Dec 19, 2013 at 12:51
  • Yes only numeric keys at the moment.
    – Nathan W
    Commented Dec 19, 2013 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.