# Database Discussions > Microsoft SQL Server 2005 >  need help in writing T-Sql Querey

## abcdOFsql

hi There,

I have a Database table which has about 90 columns in it.
 But for writing this particular querey It needs only few of them.

I'll list them here!

Acc BegDt    EnDt       J  F M A  MY  Jn  Jy  Au  S  O  N  D 
10   1/2008   12/2008  1 1 1  1  1    1    0   0    0  0  0   0


First Querey:

"Based On The BegDt, Count the no of months that has a value>0 for acc10, and continues until it reaches a 0 value."

  Note: BegDt n EnDt are in Char DataType:

Second Querey:

"Find The Value of The  'number' . where number is the value for acc 10 based on the startdate."


  Can Any one please Help me soon. Its really very Urgne..!!

ThAnKs..

----------


## rmiao

Sounds homework, ask your classmate for help.

----------


## abcdOFsql

Come on Bro..
Its not a Homework..! This is an assigned task to me..I need to do it...Can Any one please Help me out

----------


## srikanth.mss

1. USe the CHARindex function first for finding the start month from begdt column by searching with '/'
for the above example, seems 1.

2. read all the columns start from J to D in a single column using concatenation by matching with ACC column. here dont need to check the start date.

3. store the value in one variable for the expression as arrived in step 2.

4. in the CHARINDEX function itself option of searching from which character is avaiable. the start character must be the start month. Find for Zero.

5. Whaterver the value is arrived in step 4 that would be the solution.

----------

