NewsDemon Banner

Unlike my last post on the issue, instead of simply pointing to another blog for instructions on how to query Active Directory from SQL Server, I’ll provide some useful tips on getting things all working.
Read the rest of this entry »

I have a project where each object creation script is stored in a separate file. Between the tables, views, linked servers, stored procedures, functions, jobs and schemas, this results in roughly 400 objects and therefore 400 files. Trying to run these separately for a new installation simply is not feasible; I needed a quick, automated solution to combine all files into a single build script, while at the same time easily control the order of creation so dependent objects can be created in the correct order.

The solution I settled on was to simply store the list of files in the correct order inside a plain text file. I can then use a batch or shell script to compile a single, larger file. Instead of relying on an archaic DOS batch file, I decided to teach myself a bit of Powershell.
Read the rest of this entry »

As either a DBA or DBD, undoubtedly, you’ve needed to create a user account with very specific permissions. Especially when that account is based on Windows authentication, it can be particularly difficult to test and verify the correct permissions were assigned. However, if you have the access – say, sysadmin – you can simply impersonate the account yourself and verify everything is set correctly. Here’s how:
Read the rest of this entry »

I stumbled upon an interesting concept for dealing with dates: store them in Julian day format. At first glance, I only knew the format to be some sort of ID linking to a calendar table, but in fact, the IDs were designed to match to the equivalent Julian date. This is an ingenious way to store a date for a really great reason: you get an easy-to-index key and also can coerce a meaning from the data, all in 4 bytes. Need to link to a calendar table to determine which fiscal quarter the date falls in? No problem, the join is right there. Only need the actual date for output? No join needed, just convert the value to Gregorian date. Here are a couple of conversion functions for that specific task.

Convert Julian to Gregorian:

1
2
3
4
5
6
7
8
CREATE FUNCTION dbo.f_JulianToGregorian
(
	@JulianDay INT
) RETURNS DATETIME
AS
BEGIN
	RETURN DATEADD(dd, @JulianDay - 2415021, 0)
END

Convert Gregorian to Julian:

1
2
3
4
5
6
7
8
CREATE FUNCTION dbo.f_GregorianToJulian
(
	@GregorianDate DATETIME
) RETURNS INT
AS
BEGIN
	RETURN DATEDIFF(dd, 0, @GregorianDate) + 2415021
END

Some examples:

SELECT
	dbo.f_JulianToGregorian(2454467) [J2G]
	, dbo.f_GregorianToJulian('2008-01-01') [G2J]
	, dbo.f_JulianToGregorian(dbo.f_GregorianToJulian('2008-01-01')) [G2J2G]
	, dbo.f_GregorianToJulian(dbo.f_JulianToGregorian(2454467)) [J2G2J]

And results:

J2G                     G2J         G2J2G                   J2G2J
----------------------- ----------- ----------------------- -----------
2008-01-01 00:00:00.000 2454467     2008-01-01 00:00:00.000 2454467

In case you’re wondering, 2415021 is the number of days between January 1, 4713 B.C. (the start of the Julian calendar) and January 1, 1900 (the start of Microsoft’s date counting). Because we are limited to SQL Server’s date calculation ranges, we can only convert back to 1753 A.D. If you are fortunate enough to be working on a SQL Server 2008 system, feel free to change the datetime to datetime2, or better yet, the simple type of date. Either of those new data types will give you access to years 1 through 9999 A.D. Although I’m sure this is not a concern for most people, unfortunately, SQL Server does not provide native functionality to deal with B.C. dates.

I stumbled upon a few little gems that SQL Server 2008 includes that I hadn’t yet heard about. Although, very few are deploying SQL 2008 to production currently, these enhancements might make life programming in 2008 much easier.
Read the rest of this entry »

  • Graham Charles: I've been considering using this approach to forward individual users' e-mail, but I'm curious if th [...]
  • Paden: Ok another 15min all sorted. something between changing default account on iphone to the exchange go [...]
  • Paden: Thank you I'm sooo close! Same thing as Brandon & Krlrvr. How does one make Google calendar disp [...]
  • Yushe » Blog Archive » Conectar SQL Server con MySql: [...] Disclaimer: El árticulo arriba no es mio, es solo una traducción parcial del árticulo aqui [...]
  • Nick: Here is an extensive how to on sharing folders with Windows 7. http://www.ilertech.com/2010/09/shar [...]


This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States.