Showing posts with label flag. Show all posts
Showing posts with label flag. Show all posts

Sunday, March 25, 2012

Create a new system table

Is possible create a new table in master database with the
flag 'System'?
Thanks,
Rui OliveiraYes, if you work for Microsoft
For the rest of us NO
You should not mess with system tables and you should not be creating tables on the master database. You will not be able to do either when you move to Yukon so start developing good habits now
Regard
John|||Hi Rui
The following is the limit of what you can do:
create table mysystemtable ( ....)
go
sp_MS_marksystemobject mysystemtable
go
This table will show up as 'system' in Enterprise Manager, but NOT when you
use sp_help in Query Analzyer. You might be able to force it by making
directly updates to sysobjects, but I wouldn't do that on a production
machine.
Can you tell us why you need to do this?
--
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"Rui Oliveira" <anonymous@.discussions.microsoft.com> wrote in message
news:553e01c40046$09f66570$a001280a@.phx.gbl...
> Is possible create a new table in master database with the
> flag 'System'?
> Thanks,
> Rui Oliveira
>|||Tks
>--Original Message--
>Hi Rui
>The following is the limit of what you can do:
>create table mysystemtable ( ....)
>go
>sp_MS_marksystemobject mysystemtable
>go
>This table will show up as 'system' in Enterprise
Manager, but NOT when you
>use sp_help in Query Analzyer. You might be able to force
it by making
>directly updates to sysobjects, but I wouldn't do that on
a production
>machine.
>Can you tell us why you need to do this?
>--
>HTH
>--
>Kalen Delaney
>SQL Server MVP
>www.SolidQualityLearning.com
>
>"Rui Oliveira" <anonymous@.discussions.microsoft.com>
wrote in message
>news:553e01c40046$09f66570$a001280a@.phx.gbl...
>> Is possible create a new table in master database with
the
>> flag 'System'?
>> Thanks,
>> Rui Oliveira
>
>.
>

Tuesday, February 14, 2012

counting based on bit flag

I have a table with an id field (int) and a bit flag. example below

id flag

1 true

1 true

1 false

1 true

2 true

2 false

I am looking for a query that will provide me the following results if possible

id true false

1 3 1

2 1 1

Any and all help is appreciated.

My efforts so far aren't worth sharing. I am looking for completely new approaches.

Thanks a ton

Use something like this:

Code Snippet


DECLARE @.MyTable table
( ID int,
Flag smallint
)


INSERT INTO @.MyTable VALUES ( 1, 1 )
INSERT INTO @.MyTable VALUES ( 1, 1 )
INSERT INTO @.MyTable VALUES ( 1, 0 )
INSERT INTO @.MyTable VALUES ( 1, 1 )
INSERT INTO @.MyTable VALUES ( 2, 1 )
INSERT INTO @.MyTable VALUES ( 2, 0 )


SELECT
[ID],
True = sum( CASE Flag WHEN 1 THEN 1 ELSE 0 END ),
False = sum ( CASE Flag WHEN 0 THEN 1 ELSE 0 END )
FROM @.MyTable
GROUP BY [ID]


ID True False
-- -- --
1 3 1
2 1 1

|||Excellent!! Thank you so much!