If you've got a polygon you want to use as a declared variable and intersect it with a table containing existing geometry, your query (including your polygon variable declaration) would look something like this:
(MSSQL Server syntax)
declare @polygon geometry = 'POLYGON((-9486683.581 4810152.256, -9282073.762 4821688.121, -9262037.786 4625578.413, -9477576.319 4628614.167, -9486683.581 4810152.256))'
select * from tablename
where tablename.geom.STIntersects(@polygon) = 1
Edit: QGIS only way , without CSV
In QGIS, import table from DB, select Processing Toolbox, Qgis Geoalgorithms -> Vector Creation Tools ->points layer from table -> select x and y
MS SQL Server way
one easy way is to create view in SQL where you add computed column. something like this STGeomFromText('POINT(' +x +' ' +y+')')
CREATE VIEW [dbo].[point_geom_text] as
SELECT
row_number() over ( order by k.id) as gid
, k.id as oid
, ('POINT('+convert(nvarchar(24),convert(decimal(18,4), p.y)) + ' ' + convert(nvarchar(24),convert(decimal(18,4), p.x))+ ' '+convert(nvarchar(24),convert(decimal(18,4), p.z))+ ')') as geomtext
FROM dbo.points k
For xy point use
('POINT('+convert(nvarchar(24),convert(decimal(18,4), p.y)) + ' ' + convert(nvarchar(24),convert(decimal(18,4), p.x))+')') as geomtext
Simple WKT for POINT is 'POINT(1 2)'
convert code is there to convert float to decimal and then to text
That will create table with geometry text column , row_number() creates unique row number.
CREATE VIEW geoms as
SELECT *, geom::STGeomFromText(geomtext, 4326) as geom FROM points_geom_text
Creates view which has geometry in your srid (4326? in your case?)
Best Answer
I'm not entirely sure what you're asking here. If you just want to do an intersect on only selected features, just select those you want from each layer and check the option to use selected features only in the intersect dialog. If your condition involves attributes of another layer, use the refFunctions plugin within the field calculator and build your expression from there.