Wednesday, March 31, 2010

SQL dynamic IN clause

declare @currentGroup varchar(20),@SQL varchar(max)
set @currentGroup = '''003'',''004'''
select @currentGroup

set @SQL = N'SELECT count(*) from [YOURTABLE] where GRNBR in (' + @currentGroup + ')'
exec (@SQL)

Friday, March 12, 2010

separate first & last name using space, SQL, SPLIT

select
SUBSTRING(elg.FirstName, (CHARINDEX(' ', elg.FirstName) + 1),LEN(elg.FirstName)) AS [LastName]
,rtrim(ltrim(SUBSTRING(elg.FirstName, 1,CHARINDEX(' ', elg.FirstName)))) AS [FirstName]
,elg.FirstName
,elg.LastName
from dbm.EgLoads elg
where elg.BatchId='{207c6838-fe87-40d1-9353-0d60055c93f2}'
and LEN(SUBSTRING(elg.FirstName, (CHARINDEX(' ', elg.FirstName) + 1),LEN(elg.FirstName))) < = 2
and len(elg.FirstName) <> 1

Thursday, February 25, 2010

Replicate, Repeat one value in C#

string.Concat(System.Collections.ArrayList.Repeat("0", 66).ToArray());

Convert string to Decimal in C#

(Convert.ToInt32(clm.OutOfPocketAmount) >= 0 ? (Double.Parse((clm.OutOfPocketAmount.ToString().Substring(1))) / 100).ToString("F2") : clm.OutOfPocketAmount.ToString().Substring(0, 1) + (Double.Parse((clm.OutOfPocketAmount.ToString().Substring(1))) / 100).ToString("F2"))

Friday, February 12, 2010

cannot convert between unicode and non-unicode string data types, SSIS

SSIS error:

solution
http://www.mssqltips.com/tip.asp?tip=1393

#database side

1) change the column width in database table for the error coulumn.

#SSIS package side

1) Right click 'Flatfile editor' and select 'Advanced' editor
2) Go to 'Input & Output Properties'
3) Expand 'Flat File Source Output
4) Expand the 'Output columns'
5) Select Error column and change the length.

-- Yup, refresh you're OLEDB connection with updated table information.

ready to go...

Sunday, January 31, 2010

good article

"In one of the meetings, he articulated beautifully the importance of maintaining proper work-life balance. He opined that simple attributes such as prior planning and prioritising could help achieve the right balance. In another, he talked about the importance of investing time and resources on research."



http://getahead.rediff.com/report/2010/jan/19/career-taking-meetings-with-narayana-murthy.htm

Tuesday, January 19, 2010

The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

--Error code
DECLARE @dt VARCHAR(10)
SET @dt = '12012009'
SELECT CAST(@dt AS DATETIME)

--Working code
DECLARE @dt VARCHAR(10)
SET @dt = '20091201'
SELECT CAST(@dt AS DATETIME)