Brett Kaiser (x002548) Blog

Not Just a Number - Brett Kaiser

XML, SQL & DB2 V10

…or I guess it could be any platform.. Webcast/Conf Call on Monday…IBM Rep after 3 hours…I piped in… X002548: "ummm, excuse me, so are you saying that XML database models outperforms the relational model? Read more →

Next Available Date

Saw a post the other day on SQLTeam.  The OP Asked: "If I supply a Date, How can I get the next available date, that is not a holiday, and is not on the weekend. Read more →

DB2 OS/390 Database COPY and RESTORE

Hey there!!!!! In the SQL Server world, if you want to create a database on a same server instance, from an existing database, all you have to do is something like: RESTORE DATABASE <db_name>FROM DISK = '\<file path>&lt;file name>'WITH MOVE '<logical data file name>_data' TO '\<file path>&lt;file name>. Read more →

Parsing String in SQL Server Hack

Alrighty Then How to Parse a string in SQl…not always easy…I imagine it really shouldn't have been difficult for M$ to make some T-SQL extensions, but they didn't (or at least up to 2k5…gotta look more into 2k8) Even in REXX we had some nice features…like MASK, WORD, WORDS, etc. Read more →

Replace a Character Anywhere in a DB

Ran across this thread http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=135575 And figured I'd post this. The code below will generate update statement for all tables that have a char data type. It will then replace a quote (") with an empty sting Guess you could automate this, but this is simple enough. Read more →

How can I update Multiple Tables at once

"CAN'T BE DONE" – Crazy boy Well at first glance, that may very well be the answer, as in this thread: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=100207 Now, this might not be what the OP is looking for, but if you employ a partitioned view, then yes, it's doable cut and paste the sample code to see it in action USE Northwind GO CREATE TABLE myTable99 (Col1 int PRIMARY KEY CHECK (Col1 BETWEEN 1 AND 10), Col2 varchar(50)) CREATE TABLE myTable98 (Col1 int PRIMARY KEY CHECK (Col1 BETWEEN 11 AND 20), Col2 varchar(50)) GO INSERT INTO myTable99(Col1, Col2) SELECT 1, 'x' UNION ALL SELECT 2, 'y' UNION ALL SELECT 3, 'z' INSERT INTO myTable98(Col1, Col2) SELECT 11, 'x' UNION ALL SELECT 12, 'y' UNION ALL SELECT 13, 'z' GO CREATE VIEW myView99 AS SELECT Col1, Col2 FROM myTable99 UNION ALL SELECT Col1, Col2 FROM myTable98 GO SELECT * FROM myView99 UPDATE myView99 SET Col2 = 'x002548' WHERE Col2 = 'z' SELECT * FROM myView99 /* DROP VIEW myView99 DROP TABLE myTable99, myTable98 */ Read more →

Because you're mine, I walk the line

....ummm, well, that "line" would be walking through a line in a family tree. I saw a post the other the day that asked, if I know a relative somewhere in a families "lineage", how can I find the entire family tree from top to bottom. Read more →

Alias to be or not to be

EDIT: This is bizzare..I ran multiple table joins, and reran it ovr and over, and the times are always different and one time one is faster than the othe and other times it's the other wway around. Read more →

Add Foreign Keys Back to the Database

"OK Brett, Now that I Removed all my Foreign Keys to Truncate the Data, Now What? I'm Hosed! Thanks a bunch" OK, Well....sorry to keep you hangng out there. But, if you followed the code in the above link you will have all of the RI saved to the work table, so now all you need to do is replay it. Read more →

Collecting Requirements For Key Information

I've been asked to assist (this time BEFORE Project initiation for a change) in the developmennt of a new application. The Business Liason/Tech group that is doing this has been collecting requirements (basically reviewing an EXCEL Spreadsheet on steriods) and is coming up with a data model. Read more →

SET Versus SELECT (Or, Who Really Cares Anyway)

EDIT: As Tara points out: Vyas did this test quite some time ago: http://vyaskn.tripod.com/differences_between_set_and_select.htm Either I never read it, or I forgot I read it. Well hopefully I pulled some different points together differently here than Vyas did, and at the very least, I hope I made my feeling clear about a program that has to loop over 2 million times. Read more →

Generate Triggers for all Tables

Well, I did this originally to generate triggers for all tables in a database to audit data changes, and that is simple enough, just move the entire row from the deleted table to a mirrored audit table. Read more →

Hierarchies with a twist…rocks, no salt

EDIT: The script has been repaired and paired down. Basically this "solution" assigns a derived value to each entity...which I called codex for lack of better term. Each Child inherits their Parents Codex node signature. Read more →

How do I find all the tables referenced by Stored Procedures or Functions

Like this SELECT o.name, t.TABLE_NAME, c.text FROM syscomments c JOIN sysobjects o ON c.id = o.id JOIN INFORMATION_SCHEMA.Tables t ON c.text LIKE '%'+t.TABLE_NAME+'%'   Legacy Comments Peter DeBetta, Microsoft MVP - S 2006-09-22 re: How do I find all the tables referenced by Stored Procedures or Functions Actually, that isn't entirely reliable if the code of the procedure is longer than 8000 characters. Read more →

Stored Procedure Logging

Every so often, someone asks, "How do I know who executed a SQL Statement against my database". Well you can either have SQL Profiler running all the time (which can be very expensive), or you can use Lumingent's Log Explorer. Read more →

Finding Trade and Receipt fallout

A director came to me asking if a set based approach could be used to find the fallout for trades and receipts. Even though they handed the work off already. The developer used COBOL to compare the 2 file and did "spin-up" processing to match a trade to a receipt. Read more →