Bug using DATEPART function in a SQL Server Stored Procedure

0

Posted by fred | Posted in Database, tutorial | Posted on 08-02-2012

 

I had to make a weekly export of regional data. To avoid server overload, it was decided to run the stored procedure with a different parameter (region) every day.

 

Using the following stored procedure, the PROC was working fine in SQL Server management studio. When running this stored proc from a C# program on my workstation, I was getting a different resultset (i.e. REGION_C instead of REGION_B.).

 

ALTER PROC [dbo].[sp_TSV_regionalInformation] AS
DECLARE @REGION VARCHAR(8)

DECLARE @WD INT;
SET DATEFIRST 1
SET @WD = DATEPART (weekday , CURRENT_TIMESTAMP);

– Based on the day of the week, will pick up a different Region
IF @WD = 1 SET @REGION=’REGION_A’
IF @WD = 2 SET @REGION=’REGION_B’
IF @WD = 3 SET @REGION=’REGION_C’
IF @WD = 4 SET @REGION=’REGION_D’
IF @WD = 5 SET @REGION=’REGION_E’
IF @WD = 6 SET @REGION=’REGION_F’

 

SELECT x, y, z FROM table WHERE theRegion = @REGION

 

As a matter of fact, the Stored Procedure will use the weekday defined at the client level, thus having different results from my C# application and the SQL management studio (1st day of the week set up differently).

 

In order to fix that, the following statement should be added before the DATEPART function:

SET DATEFIRST 1

Once, this statement has been inserted, the first day if the week will be Monday (in this case) all the time!

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)

Geoserver SQL view layers returning byte[] instead of Geometry when running on MySQL

2

Posted by fred | Posted in Application, Database, tutorial, Web | Posted on 04-08-2011

Tags: , , , , ,

 

 

 

 

 

 

The issue: When querying a MySQL database from a GeoServer SQL view layer, the shape column return a byte[] data type instead of a Geometry data type.

 

How to fix it: (easy as 1, 2, 3 and 4):

1. Download the latest JDBC driver from the MySQL website

2. Copy the extracted file to your WEB-INF/lib folder (/var/www/geoserver/webapps/geoserver/WEB-INF/lib/ in my case)

3. Delete the other version of the driver (GeoServer is currently packaged with the version 5.1.5 – mysql-connector-java-5.1.5.jar)

4. Restart your Geoserver

 

and voila! your SQL query should now return a geometry field.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)

Getting Started With PostGIS: An almost Idiot’s Guide

0

Posted by fred | Posted in Database, tutorial | Posted on 15-07-2011

Tags: , , ,

Another useful guide on how to setup PostGIS and on how to import data

http://bit.ly/pFhLQK

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)