Results 1 to 4 of 4

Thread: [RESOLVED] SQL LOGIC hELP

  1. #1

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Resolved [RESOLVED] SQL LOGIC hELP

    Good Day All

    i have a table that carries a Field that has data like this


    Code:
    10101010101010
    Now the Function that adds this 1's and 0's is working like this. If its selected insert "1" else "0", So if i can interpret the above if will be

    Code:
    1 3 5 7 9 11 13
    the only thing that am interested in is "1's", if i can display their Position in a SQL Query i will be happy

    i want to take these Values from a SQl table and Bind them to a Gridview. Remember the Number of Zeor's can increase , but the Limit is 63 including the "1's" and "0's".


    Thank you
    Last edited by vuyiswamb; Feb 23rd, 2009 at 06:32 AM.

  2. #2
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: SQL LOGIC hELP

    Hope this will help you
    Code:
    declare @S as nvarchar(63)
    set @S = '10101010101010'
    
    declare @NS as nvarchar(128)
    set @NS=''
    declare @Len as int
    SET @Len = LEN(@S)
    
    declare @Counter as int
    SET @Counter = 1
    WHILE @Counter < = @Len
    BEGIN
    	if (SUBSTRING(@S,@Counter,1)='1')
    		set @NS = @NS + ' ' + convert(nvarchar,@Counter)
    	SET @Counter = @Counter + 1
    END
    select @NS
    If you wish you can create SQL function or Procedure with above logic
    __________________
    Rate the posts that helped you

  3. #3
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: SQL LOGIC hELP

    do you already have some code for this? could you post it?

  4. #4

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    830

    Resolved Re: SQL LOGIC hELP

    Thanks , your Code Solved my Problem and you got your Rating.

    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width