Entries Tagged as "SQL Server"

Change SQL Server bit field to the opposite value: "NOT bit_fld"

I had a DB column named 'mai_confirmed' (confirmed for mailing), but I needed a column with the value for 'needsConfirmation' for a mailing component.

Or, to say it codish: needsConfirmation = not mai_confirmed

I tried SELECT !mai_confirmed AS needsConfirmation, and also SELECT (NOT mai_confirmed) AS needsConfirmation, but those didn't work.

The trick is:

SELECT mai_confirmed + 1 % 2 AS needsConfirmation

Even though the resulting value is not a bit field anymore, it does return either NULL, 1, or 0. Which was fine enough for me ;-)

8 Comments

Custom sql server 2005 backup script

I finally managed to fully automate the backups for my sql server 2005 express edition databases. The product is free, and therefor great. But the limitations seem to be the jobs you can't add, and the scheduling that isn't available.

So, I made this small but handy Stored procedure, which queries all database names, loops through them, and creates a backup file for each of them:

No Comments