Thursday, March 17, 2011

How to Declare Variables in MS-SQL Server Management Studio

Most of the projects I work on have some kind of database interaction and some of them require variables to be the passed to the queries at runtime.

I typically test my queries against the database using Microsoft SQL Server Management Studio and being able to use variable on my queries there is a big help.

Here is a quick hint to use variables with MS-SQL Server Management Studio:


-- Database to use
USE OSBC;

-- Declare the variable you need
DECLARE @AcctNumber varchar;

-- Set the value of the variable
BEGIN
SET @AcctNumber = 1
END

-- Run the query testing the paramenters
select * from contacts
WHERE AccountNumber = @AcctNumber


Here is a screenshot of my test:



Pretty simple stuff yet useful...

Setting Up Local Environment for Developing Oracle Intelligent Bots Custom Components

Oh the joy of having a local development environment is priceless. For most cloud based solutions the story repeats itself being hard to tr...