Here's my preferable way to do if else statements in T-SQL. The syntax is pretty simple.
select
case when conditional
then 'true case'
else 'false case'
end
as conditionalValue
Of course the comparisson opporators are <, =, <=, >, <>, >=, IS NULL, and IS NOT NULL.
Enjoy..
Wednesday, February 28, 2007
Inserting based on Select
I often forget this syntax.
INSERT tablename (value1, value2)
SELECT value1, value2
FROM someothertable
WHERE somewhereclause
I often forget this syntax. It of course inserts the row or rows returned by the select into the table given on the insert line.
Tuesday, February 27, 2007
Selecting Column Names, (and Info)
I've been working a lot with ugly CSV files with about 4 trillion rows. (Ok, not 4 trillion, but enough to get sick of them) I found myself looking for rows w/ given names, only to scroll through them when I wasn't going slowly enough. So to fix that I found this
select column_name, data_type, character_maximum_length from information_schema.columnsWhich makes things much easier :)
where table_name = 'myTable'
Monday, February 26, 2007
NVARCHAR vs. VARCHAR
I always wondered what the difference was:
NVARCHAR is used to hold unicode characters used to hold multilingual data. It also takes up twice as much space to hold 1 character as it's VARCHAR counterpart, due to the need for those extra bits.
So for the most part...unless you've got a db in multiple languages, USE VARCHAR!
NVARCHAR is used to hold unicode characters used to hold multilingual data. It also takes up twice as much space to hold 1 character as it's VARCHAR counterpart, due to the need for those extra bits.
So for the most part...unless you've got a db in multiple languages, USE VARCHAR!
Thursday, February 22, 2007
Disabling your Isight
To get rid of the creepy camera that you see at the top of your new shinny mac?
This link gives a good description
http://techslaves.org/index.php?page=10
Still looking for a way to disable the built in microphone in a similar way.
This link gives a good description
http://techslaves.org/index.php?page=10
Still looking for a way to disable the built in microphone in a similar way.
Thursday, February 15, 2007
SQL Server 2005 DB Restore
I found myself getting the following error
TITLE: Microsoft SQL Server Management Studio
------------------------------
Restore failed for Server 'MyServer'. (Microsoft.SqlServer.Smo)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.2047.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Restore+Server&LinkId=20476
------------------------------
ADDITIONAL INFORMATION:
System.Data.SqlClient.SqlError: RESTORE cannot process database 'MYDB' because it is in use by this session. It is recommended that the master database be used when performing this operation. (Microsoft.SqlServer.Smo)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.2047.00&LinkId=20476
------------------------------
BUTTONS:
OK
------------------------------
So after some googleing I found this.
USE master
RESTORE DATABASE MYDB
FROM DISK = 'C:\Documents and Settings\username\Desktop\myBackUpFile.bak'
this sets the table to master, and runs the same querry the wizard would. (Although this is a deprecated function)
TITLE: Microsoft SQL Server Management Studio
------------------------------
Restore failed for Server 'MyServer'. (Microsoft.SqlServer.Smo)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.2047.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Restore+Server&LinkId=20476
------------------------------
ADDITIONAL INFORMATION:
System.Data.SqlClient.SqlError: RESTORE cannot process database 'MYDB' because it is in use by this session. It is recommended that the master database be used when performing this operation. (Microsoft.SqlServer.Smo)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.2047.00&LinkId=20476
------------------------------
BUTTONS:
OK
------------------------------
So after some googleing I found this.
USE master
RESTORE DATABASE MYDB
FROM DISK = 'C:\Documents and Settings\username\Desktop\myBackUpFile.bak'
this sets the table to master, and runs the same querry the wizard would. (Although this is a deprecated function)
Subscribe to:
Posts (Atom)