Validus … talkin bout <code> n sh!t

23Nov/110

How to check for active transactions

Posted by Joey

Debugging an issue today at work, and needed to find if there was any uncommitted transactions or active transactions.

There’s a couple of ways to do this:

1
Thanks Pinal Dave – more from his blog post here.

Also you can use dbcc opentran Or SELECT @@TRANSCOUNT

So, if you’re like me and what to see this in action… Continue reading

Filed under: Databases No Comments
1Jul/110

How to find the name of a sql server

Posted by Joey

Fast way to get a sql server name, great if you’re dealing with multiple sql servers.

1

This will return the Windows computer name on which the sql server instance is currently running on.
It will return NULL if there is an error.

1

This will return the instance & computer name

[code… Continue reading

Filed under: Databases No Comments
16May/110

how to select columns from a stored proc

Posted by Joey

Okay so recently I’ve had to select only certain columns from a large stored proc that may return like 4 columns. How to do this?

DECLARE @tableVar table (Surname varchar (100), FirstName varchar(255), Email varchar(100), Age int)
INSERT INTO @tableVar EXEC dbo.usp_getSomeData
SELECT Surname, Email FROM @tableVar… Continue reading

Filed under: Databases No Comments
19Apr/110

Passing a nullable/blank field to a WHERE statement

Posted by Joey

I’ve used this piece of code in many places lately to check if a field is nullable or blank – used mainly as a default value.

AND
(
@ResultType = ” OR
@ResultType ” AND ResultType IN(@ResultType)
)… Continue reading

Filed under: Databases No Comments
5Apr/110

grant execute for a stored proc to application role

Posted by Joey

simple script incase you forget:

grant exec on to… Continue reading

Filed under: Databases No Comments
25Nov/100

Using DELETE FROM with INNER JOIN

Posted by Joey

Ever needed to delete a table? Oh wait it’s joined to another. Well here’s some how you do it… the right way!

For MSSQL

DELETE Users
FROM Users u
INNER JOIN
Profiles p on u.UserID = p.UserID
WHERE u.UserIsArchived = 1

For MySQL

DELETE u, p
FROM Users u
INNER JOIN Profiles p ON u.UserID = p.UserID
WHERE u.UserIsArchived = 1… Continue reading

Filed under: Databases, Stuff No Comments
12Nov/100

Example script for create table in h2

Posted by Joey

Just figured I’d add one of these scripts incase I forget! Haha… but just if you’re curious, it not different to MySQL.

DROP TABLE IF EXISTS Players;
CREATE TABLE Players
(
PlayerID int identity,
FirstName varchar(255),
LastName varchar(255)
);

INSERT INTO Players
(FirstName, LastName)
VALUES
(‘Joey’, ‘Daly’);

Here’s the docs for H2 DB:

Filed under: Databases, Stuff No Comments
12Nov/100

Fusegrid SDK

Posted by Joey

Been using Fusegrid SDK, it’s fantastic for people who just want to start coding Coldfusion with zero time wasted on setup.

Normally you’ll need to setup a web server, then download ColdFusion and then work out what database you want… painful!

Fusegrid comes bundled with Railo + H2 Database, and CFWheels :D

Get it here: http://www.fusegrid.com/sdk/… Continue reading

Filed under: CF, Databases, Stuff No Comments
15Oct/100

Concat Rows into a string

Posted by Joey

I had this problem a while ago where I needed to do a really big UPDATE sql statement using the IN clause. So rather than coping all the ids out and then adding a comma at the end of it you can concat the id rows into a string – thanks A-ton!… Continue reading

Filed under: CF, Databases, Stuff No Comments
11Jun/100

Downloading an image from database

Posted by Joey

A project I’m working on involves storing asset references in a database and then later downloading the images. Why? because it takes bloody ages!

So assuming you have a table called Assets, and all the right fields. There’s two options, using cfhttp or cfimage (cf8+).


<cfset pathToActualImage = “http://www.google.com/images/hello.jpg” />
<cfset tempFileName = “test.jpg” />
<cfset tempPath = “C:\temp\” />

<cfhttp url=”#pathToActualImage#” file=”#tempFileName#” path=”#tempPath#”>
Filed under: CF, Databases, Stuff No Comments