User Tools

Site Tools


Cheat sheet for MSSQL 2008

Get table names from database

SELECT TABLE_NAME FROM information_schema.tables

Show table structure

EXEC sp_columns <tablename>

Limit output to x lines

SELECT top <x> * FROM <tablename

Dates and times

Date conversion

The magic number in the convert function determines the datestyle: 120 == ODBC canonical.

More about converting][here

Select events that are active at a certain time:

SELECT event, starttime, endtime
WHERE  CONVERT(datetime,'2012-08-04 12:00:00',120) BETWEEN starttime AND endtime

Python and mssql


Error message: “Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier.”

can be resolved by adding tds_version = 8.0 to your odbc.ini

(the Why is nicely summarised e.g. by Ubuntitis

mssql.txt · Last modified: 2012/09/26 14:02 by mantis