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: Yesterday @ 8:50 AM
Points: 4,425, Visits: 3,417
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: Wednesday, July 30, 2014 10:52 PM
Points: 483, Visits: 244
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, February 6, 2014 4:15 AM
Points: 1,242, Visits: 1,546
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: Yesterday @ 9:28 AM
Points: 13,570, Visits: 10,447
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 LessThanDot.

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: Friday, June 27, 2014 9:14 PM
Points: 53, Visits: 166
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
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 1:20 AM
Points: 834, Visits: 1,522
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, February 6, 2014 4:15 AM
Points: 1,242, Visits: 1,546
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, June 24, 2014 6:38 PM
Points: 1,371, Visits: 1,560
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
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Yesterday @ 2:55 AM
Points: 600, Visits: 880
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


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 8:26 AM
Points: 1,803, Visits: 2,168
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