Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

Back to basics Expand / Collapse
Author
Message
Posted Monday, July 1, 2013 9:31 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 9:27 AM
Points: 4,642, Visits: 3,848
Comments posted to this topic are about the item Back to basics
Post #1469281
Posted Monday, July 1, 2013 11:05 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Tuesday, May 12, 2015 10:14 AM
Points: 490, Visits: 253
Great question on data types. Thanks.
Post #1469287
Posted Monday, July 1, 2013 11:47 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, July 23, 2015 2:40 AM
Points: 1,242, Visits: 1,549
Good question. But i never feel to use "Bitwise AND" (&) in real working scenario. It will good, if anyone come with some real working example.



Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
www.GrowWithSql.com

Post #1469293
Posted Tuesday, July 2, 2013 12:49 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 7:25 AM
Points: 14,513, Visits: 12,557
Nice question, thanks!



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1469315
Posted Tuesday, July 2, 2013 2:30 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, July 27, 2015 3:37 AM
Points: 56, Visits: 175
What if i define @S as BIGINT

Can you give me a real time scenario as in this operator would be useful. i am just a bit curious as i have never used used it.
Post #1469341
Posted Tuesday, July 2, 2013 2:47 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, July 3, 2015 1:31 AM
Points: 1,015, Visits: 1,612
Danny Ocean (7/1/2013)
Good question. But i never feel to use "Bitwise AND" (&) in real working scenario. It will good, if anyone come with some real working example.

It provides a neat way of sending multiple options as a single integer parameter.

For example, let's say you have a table called "Locations" with 2 columns, LocationID and Location, containing the following values:

LocationID Location
1 London
2 Dublin
4 Paris
8 Berlin
16 New York
etc...

Then you could select any combination of Location values as follows:
declare @Selection int;
set @Selection=10; -- (this will select Dublin and Paris, because Dublin's LocationID plus Paris's LocationID equals 10)

select
Location
from
Locations
where
LocationId & @Selection>0;

Post #1469346
Posted Tuesday, July 2, 2013 3:25 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, July 23, 2015 2:40 AM
Points: 1,242, Visits: 1,549
martin.whitton (7/2/2013)
Danny Ocean (7/1/2013)
Good question. But i never feel to use "Bitwise AND" (&) in real working scenario. It will good, if anyone come with some real working example.

It provides a neat way of sending multiple options as a single integer parameter.

For example, let's say you have a table called "Locations" with 2 columns, LocationID and Location, containing the following values:

LocationID Location
1 London
2 Dublin
4 Paris
8 Berlin
16 New York
etc...

Then you could select any combination of Location values as follows:
declare @Selection int;
set @Selection=10; -- (this will select Dublin and Paris, because Dublin's LocationID plus Paris's LocationID equals 10)

select
Location
from
Locations
where
LocationId & @Selection>0;



Thanks martin




Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
www.GrowWithSql.com

Post #1469362
Posted Tuesday, July 2, 2013 3:32 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, December 2, 2014 9:20 AM
Points: 1,372, Visits: 1,567
martin.whitton (7/2/2013)

It provides a neat way of sending multiple options as a single integer parameter.


Nice example Martin


~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter

Post #1469365
Posted Tuesday, July 2, 2013 4:41 AM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Today @ 3:01 AM
Points: 796, Visits: 1,186
Danny Ocean (7/1/2013)
Good question. But i never feel to use "Bitwise AND" (&) in real working scenario. It will good, if anyone come with some real working example.


Hi, another example where BIT comparison is useful, msdb..sysschedules keeps the freq_interval in bitwise value :)

use [msdb]
go
create table #DaysOfWeekBitWise(
[bitValue] [tinyint] NOT NULL PRIMARY KEY,
[name] [varchar](10) NULL,
)
go
insert into #DaysOfWeekBitWise ([bitValue], [name])
values (1, N'Sunday')
, (2, N'Monday')
, (4, N'Tuesday')
, (8, N'Wednesday')
, (16, N'Thursday')
, (32, N'Friday')
, (64, N'Saturday')
go

select j.name
, case when j.enabled = 1 then 'Yes' else 'No' end as enabled
, jsch.next_run_date
, jsch.next_run_time
--, jst.*
, s.freq_interval
, ISNULL( STUFF( (SELECT N', ' + name FROM #DaysOfWeekBitWise AS B WHERE B.bitValue & s.freq_interval = B.bitValue FOR XML PATH('') ), 1, 2, '' ), 'None' ) AS backup_schedule
from msdb.dbo.sysjobs as j
left join msdb.dbo.sysjobschedules as jsch
on jsch.job_id = j.job_id
left join msdb.dbo.sysschedules as s
on s.schedule_id = jsch.schedule_id
order by j.name
go
drop table #DaysOfWeekBitWise
go

Cheers
Post #1469385
Posted Tuesday, July 2, 2013 4:48 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Wednesday, June 24, 2015 5:03 PM
Points: 2,106, Visits: 2,251
Patibandla (7/2/2013)
What if i define @S as BIGINT

Can you give me a real time scenario as in this operator would be useful. i am just a bit curious as i have never used used it.


The last time I saw it used in a database was similar to the city option example given. In this instance, it was used to determine permissions across multiple databases by comparing the database 'lock' (say '01001001') to the user 'key' (say '11011001'). If the bitwise AND came back the same as the database lock, then you had access to the database.

I would note the field is semantically overloaded. But, that is a different discussion.


Please don't go. The drones need you. They look up to you.
Connect to me on LinkedIn
Post #1469387
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse