--To Draw a line string
----------------------------
SELECT geometry::STGeomFromText(
'LINESTRING(0 0,1 1)', 0 );
--To Draw Polygons
-----------------------------
SELECT geometry::STGeomFromText(
'POLYGON((0 0,0 1,1 1,1 0,0 0))',
0 );
SELECT geometry::STGeomFromText(
'MULTIPOLYGON(
((0 0,0 1,1 1,1 0,0 0)),
((2 0,2 1,3 1,3 0,2 0)))', 0 );
--Fetch Data from Table and Form chart
--------------------------------------------------
--Create Table
CREATE TABLE [dbo].[Sales](
[FY] [int] NOT NULL,
[Sales] [int] NOT NULL
) ON [PRIMARY]
--Form chart from Results of table
DECLARE @WKT AS VARCHAR(8000);
SET @WKT =
STUFF(
(SELECT ',' + CAST( FY AS CHAR(4) ) + ' ' + CAST( Sales AS VARCHAR(30) )
FROM Sales
ORDER BY FY
FOR XML PATH('')), 1, 1, '');
Select @WKT
SELECT geometry::STGeomFromText( 'LINESTRING(' + @WKT + ')', 0 );
--Form Chart with some manipulations in table Result
DECLARE @WKT AS VARCHAR(8000);
SET @WKT =
STUFF(
(SELECT ',((' +
CAST( FY - 0.3 AS VARCHAR(30) ) + ' 0,' +
CAST( FY - 0.3 AS VARCHAR(30) ) + ' ' +
CAST( Sales AS VARCHAR(30) ) + ',' +
CAST( FY + 0.3 AS VARCHAR(30) ) + ' ' +
CAST( Sales AS VARCHAR(30) ) + ',' +
CAST( FY + 0.3 AS VARCHAR(30) ) + ' 0,' +
CAST( FY - 0.3 AS VARCHAR(30) ) + ' 0))'
FROM Sales
ORDER BY FY
FOR XML PATH('')), 1, 1, '');
SELECT geometry::STGeomFromText( 'MULTIPOLYGON(' + @WKT + ')', 0 );
Ref : http://sqlmag.com/t-sql/generating-charts-and-drawings-sql-server-management-studio