August 2009 Entries

If you want to reformat data, use the function convert as shown:

select convert(varchar, cast(18 as integer)) as 'a number'
Posted On Friday, August 7, 2009 5:21 AM | Comments (1)
Filed Under [ SQL ]


Let's say you've developed a stored procedure that assigns a count value to a variable which looks like this:

SELECT @HasDefaultShipTo = count(*)
  FROM StakeHolderLoc_Assoc 
    WHERE assoc.StakeHldrID = @StkhldrID

When you execute to compile you will see the error:

Msg 4104, Level 16, State 1, Procedure MetroDevETL_1, Line 80
The multi-part identifier "assoc.StakeHldrID" could not be bound.

The reason this error appears is because you have forgotten to associate/bind the table to "assoc". The corrected SQL will look like this:

SELECT @HasDefaultShipTo = count(*)
  FROM StakeHolderLoc_Assoc assoc
    WHERE assoc.StakeHldrID = @StkhldrID