Tuesday, September 30, 2008

SQL 2005: Delete Records Using Another Table

DELETE tobeupdated_table FROM tobeupdated_table  a
WHERE a.tableID = @ID_in
       AND a.otherTableID IN 
           ( SELECT otherTableID  FROM otherTable b
                    WHERE b.someField = @someValue_in
           );

Monday, September 22, 2008

C#: DataTable row conversions.

double value = double.Parse(dr["value"].ToString());

This would parse a value in a datatable field as a double.

Wednesday, August 27, 2008

Python: Datetime Math

#start code
import datetime
from datetime import datetime as dt
oneDay = datetime.timedelta(days=1)
tomorrow = dt.today()+oneDay
kmlTimeFormat = tomorrow.strftime("%Y-%m-%dT%H:%M:%SZ")
#end code

timedelta resides in the datetime module
today() resides in the datetime.datetime module

then add timedelta (can use months, hours, days, ...) to your datetime.datetime object

I added the kml date string format because thats what i am working on at the moment.


more info

Thursday, July 31, 2008

Javascript: Confirmation Alert

if ( confirm("are you sure?") )
alert( 'you chose yes' );
else
alert("you chose no");

Thursday, July 17, 2008

SQL: Update a table using another table

UPDATE Table1
SET Table1.fieldToBeUpdated=
(SELECT Table2.fieldToUpdateFrom
FROM Table2
WHERE Table2.commonID= Table1.commonID)
)

WHERE EXISTS (
SELECT Table2.fieldToUpdateFrom
FROM Table2
WHERE Table2.commonID= Table1.commonID)
)

Wednesday, July 16, 2008

SQL 2005: Unpivot

SELECT recordID, oldColumnNames , newValue
FROM (SELECT recordID, [column1], [column2], [column3] FROM Table) AS p
UNPIVOT (newValue FOR oldColumnNames IN ([column1], [column2], [column3])) AS s

ok this is a little weird bear with me.

its going to take column1, 2, 3 and combine their data into one column. It will create a new column which I've called oldColumnNames and the old column name will be value of the oldColumnNames column.

so

id, column1, column2, column3
1, a, b, c
2, d, e, f

becomes
id, oldColumnNames, newValue
1, column1, a
1, column2, b
1, column3, c
2, column1, d
2, column2, e
2, column3, f

Monday, June 30, 2008

SQL: Insert CSV into Table

BULK INSERT OrdersBulk
FROM 'c:\file.csv'
WITH
(
FIRSTROW = 2,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)

stole it from here