I have the following data in a database table column named timeSchedule
00100110
00010100
00110000
00110011
Boolean addition would result in
00110111
Is there a way to do this in sql? Something like select sumboolean(timeSchedule) from myTable
Someone asked for DDL+DML.. here is an example:
CREATE TABLE [dbo].[myTable](
[musPracticeID] [int] IDENTITY(1,1) NOT NULL,
[chosenDate] [datetime] NULL,
[timeSchedule] [nvarchar](50) NULL CONSTRAINT [DF_myTable_schedule] DEFAULT (N'0000000000000000')
)
INSERT INTO myTable (chosenDate, timeSchedule)
VALUES (’06/07/2015’, ’01000100’);
OK, Now that we have the DDL (unfortunately without the DML but only one row). we can provide a solution :-)
firstly! I highly recommend NOT TO USE the solution above, THERE IS NO NEEDS for loops even you not use fixed data length we know the max len (50).
Secondly! If you are going to parse text then you should use SQLCLR and not looping and parsing using T-SQL, in most cases as this one as well.
Third :-) here is simple example for simple solution. I only used the first 10 chars... you can continue to 50... you can use dynamic query in order to create the query if you dont want to write it yourself manually (There are other solutions as well, I recommend to check execution plan and IO used in order to select the best solution for u):