Friday, 31 August 2007

Rounding datetime to midnight

SQL Server
select dateadd(dd,0, datediff(dd,0, datetimeval)) as date_at_midnight

MySql
SELECT DATE_FORMAT(now(), '%Y-%m-%d 00:00:00')

To copy files from one Linux server to another

scp *_200704.* root@ipaddress:/var/lib/mysql/dbname/

Run a script for all servers

for /f %i in (servers.txt) do SQLCMD -S%i -i C:\myscript.sql

Changing the Default Collation

Shutdown Microsoft® SQL Server™ 2000, and then run Rebuildm.exe. This is located in the Program Files\Microsoft SQL Server\80\Tools\Binn directory.
In the Browse for Folder dialog box, select the \Data folder on the SQL Server 2000 compact disc or in the shared network directory from which SQL Server 2000 was installed, and then click OK.
Click Settings. In the Collation Settings dialog box, verify or change settings used for the master database and all other databases.
Initially, the default collation settings are shown, but these may not match the collation selected during setup. You can select the same settings used during setup or select new collation settings. When done, click OK.
In the Rebuild Master dialog box, click Rebuild to start the process.
The Rebuild Master utility reinstalls the master database.

we use: Latin1_General_CI_AS

Passing XML to a Stored Procedure

declare @sXML xml -- for SQL2000 use varchar(2000)
set @sXML = '

'

DECLARE @hDoc int
DECLARE @zip TABLE (PostalCode varchar(15))
exec sp_xml_preparedocument @hDoc OUTPUT, @sXML
INSERT @zip
SELECT PostalCode
FROM OPENXML(@hDoc, 'root/ZipCode')
WITH (PostalCode VARCHAR(20))
EXEC sp_xml_removedocument @hDoc
SELECT * FROM @Zip

Who's got all the terminal services sessions?

qwinsta /server:SERVERNAME

SSRS Colours

Yellow:#FFCC33
Grey: #EBEBEB
Blue: #3399CC

=iif(RowNumber(Nothing) Mod 2, "white", "#EBEBEB")

H1: 18pt
H2: 10pt 0.5cm field height
Data: 8pt 0.5cm field height
PORTRAIT:
Margins: 1cm all round
Pagesize: 21cm * 29.7cm
Full width tables start at 0.25 and finish at 18.75
LANDSCAPE:
Margins: 1cm all round
Pagesize: 29.7cm * 21cm
Full width tables start at 0.25 and finish at 27.5

Latitude/Longitude from Google Maps

To get the latitude/longitude from google maps:

1. Search for the location. The map will centre on that location.
2. Paste the following text into the address bar:
javascript:void(prompt('',gApplication.getMap().getCenter()));


If you scroll the map then this will show a false location.

To display a latitude/longitude position type them into google maps search box separated by a space.