Showing posts with label sqlserver. Show all posts
Showing posts with label sqlserver. Show all posts

Thursday, March 29, 2012

Booleans, SqlServer, and VB

Hi,

The three above seem to form an evil combination. ;-)

For now, I use varchar(5) in my SqlServer 2000 db and fill it with "True" or "False", which VB understands as boolean values in my .aspx/.aspx.vb pages.

Is there no way of using Bit instead in SqlServer, or even 0/1, and easily bind it in VB? How do others do it? (I've only seen other people struggling with this, and not any solution).

I can't understand why a language such as VB cannot be allowed to understand both True/False, 1/0, and Y/N!

Muchos gracias in advance,

Pettrer

I do not know what about Y/N but 0/1 in VB is a little opposite because is 0/-1 so -1 is true in VB and 1 is true in SQL Bit field.

Thanks

|||

Thanks, but the problem is that VB only writes "True" and "False" to the database. Of course i might be able to change it in the INSERT/UPDATE statements, but then I read somewhere that booleans are not indexed in SqlServer, so I guess that it's bo point using it anyway. Am i wrong in this assumption? Please help.

Pettrer, very puzzled ;-)

|||

If your field is bit field is stored on SQL as 0 or 1 but in gridView in VB is be displayed as True/False by default (or as check box if you ask for this )check this code :

select

cast(-10asbit) true,cast(0asbit) false,cast(1asbit) true,cast(10asbit) true

As you could see from this example I was a little wrong in SQL looks like false is 0 and everything else is true

Thanks

|||

Yes, you're right - everything that is not 0 is true; absint - not absinth! ;-) - comes to mind...

However, my questions are (forgive me if I misunderstood your reply):

1. How do I get from the checkbox to boolean in the db (the other way becomes correct automatically )?

2. Is this a behaviour I want (ie having booleans in the db), as I read somewhere that booleans are not indexed - which sounds really strange to me, as that would affect server performance)? I could of course convert everything to 0/1 as integers, but it seems rather stupid to do that. What do people do? Is no one using VB with SqlServer?

Pettrer, puzzled! :-)

|||Use bit data type which is Ture/False in the database and you can set this column to required and with a default if you want.|||

Limno,

Thanks for replying. You're right of course, but the problem is not the SqlServer db per se, but how badly VB works together with it. I took a look in the db and realised that if I do this the boolean way, it's still one byte per entry, as they can't be divided into the bits. If I use the strings True and False, I get two bytes instead. It's really not a big deal, then (my advice to other VB developers must be to use the textual representation in the db). But it's really, really strange!

Pettrer

Boolean in sqlserver 2000 and sqlserver 2005

Hi ,
In sqlserver (2000 & 2005) for a Boolean column what datatype is best
supported in terms of performance and best practice.
For a BOOLEAN is it a
best practice to use CHAR(1) which stores (Y / N )
or
best practice to use INT which stores (0 / 1 )
Thanks In adv
ThirumaranThis depends somewhat on what you are going to do with it and how your
application will handle it. But I typically like to use a TINYINT. It only
takes up 1 byte but still allows you to expand from a simple Bool to a
status type value without changing the datatype. It is also cleaner in most
cases to deal with than a Bit datatype.
--
Andrew J. Kelly SQL MVP
"thirumaran" <thirumaran@.discussions.microsoft.com> wrote in message
news:A22D9167-8FE4-4018-85FF-84D0A0D31FBD@.microsoft.com...
> Hi ,
> In sqlserver (2000 & 2005) for a Boolean column what datatype is best
> supported in terms of performance and best practice.
> For a BOOLEAN is it a
> best practice to use CHAR(1) which stores (Y / N )
> or
> best practice to use INT which stores (0 / 1 )
> Thanks In adv
> Thirumaran
>
>
>|||It depends on your business requirements
It could be CHAR(1) which stores (Y / N ) or TINYINT 0/1 or BIT 0/1
It is worth to mention that you should not allow NULL's in that CASE or as
I said it depends on what you are trying to achive
"thirumaran" <thirumaran@.discussions.microsoft.com> wrote in message
news:A22D9167-8FE4-4018-85FF-84D0A0D31FBD@.microsoft.com...
> Hi ,
> In sqlserver (2000 & 2005) for a Boolean column what datatype is best
> supported in terms of performance and best practice.
> For a BOOLEAN is it a
> best practice to use CHAR(1) which stores (Y / N )
> or
> best practice to use INT which stores (0 / 1 )
> Thanks In adv
> Thirumaran
>
>
>

Boolean in sqlserver 2000 and sqlserver 2005

Hi ,
In sqlserver (2000 & 2005) for a Boolean column what datatype is best
supported in terms of performance and best practice.
For a BOOLEAN is it a
best practice to use CHAR(1) which stores (Y / N )
or
best practice to use INT which stores (0 / 1 )
Thanks In adv
ThirumaranThis depends somewhat on what you are going to do with it and how your
application will handle it. But I typically like to use a TINYINT. It only
takes up 1 byte but still allows you to expand from a simple Bool to a
status type value without changing the datatype. It is also cleaner in most
cases to deal with than a Bit datatype.
Andrew J. Kelly SQL MVP
"thirumaran" <thirumaran@.discussions.microsoft.com> wrote in message
news:A22D9167-8FE4-4018-85FF-84D0A0D31FBD@.microsoft.com...
> Hi ,
> In sqlserver (2000 & 2005) for a Boolean column what datatype is best
> supported in terms of performance and best practice.
> For a BOOLEAN is it a
> best practice to use CHAR(1) which stores (Y / N )
> or
> best practice to use INT which stores (0 / 1 )
> Thanks In adv
> Thirumaran
>
>
>|||It depends on your business requirements
It could be CHAR(1) which stores (Y / N ) or TINYINT 0/1 or BIT 0/1
It is worth to mention that you should not allow NULL's in that CASE or as
I said it depends on what you are trying to achive
"thirumaran" <thirumaran@.discussions.microsoft.com> wrote in message
news:A22D9167-8FE4-4018-85FF-84D0A0D31FBD@.microsoft.com...
> Hi ,
> In sqlserver (2000 & 2005) for a Boolean column what datatype is best
> supported in terms of performance and best practice.
> For a BOOLEAN is it a
> best practice to use CHAR(1) which stores (Y / N )
> or
> best practice to use INT which stores (0 / 1 )
> Thanks In adv
> Thirumaran
>
>
>

Tuesday, March 27, 2012

Boolean datatype in SQLServer 2005?

I thought there was one at long, long last, but I don't see it!
Good grief, is this possible?
SQL_Variant ... nope.
Yes, C#, but really.
Josh
Hi Josh,
What's wrong with the bit type. It's been there for ever
kind regards
Greg O
Looking to use CLR in SQL 2005. Try some pre-build CLR Functions and SP
AGS SQL 2005 Utilities, over 20+ functions
http://www.ag-software.com/?tabid=38
"jxstern" <jxstern@.nowhere.xyz> wrote in message
news:lit3q1pom5csn3lmf8m1vvq1aelqm15f4n@.4ax.com...
>I thought there was one at long, long last, but I don't see it!
> Good grief, is this possible?
> SQL_Variant ... nope.
> Yes, C#, but really.
> Josh
>

Boolean datatype in SQLServer 2005?

I thought there was one at long, long last, but I don't see it!
Good grief, is this possible?
SQL_Variant ... nope.
Yes, C#, but really.
JoshHi Josh,
What's wrong with the bit type. It's been there for ever
kind regards
Greg O
--
Looking to use CLR in SQL 2005. Try some pre-build CLR Functions and SP
AGS SQL 2005 Utilities, over 20+ functions
http://www.ag-software.com/?tabid=38
"jxstern" <jxstern@.nowhere.xyz> wrote in message
news:lit3q1pom5csn3lmf8m1vvq1aelqm15f4n@.
4ax.com...
>I thought there was one at long, long last, but I don't see it!
> Good grief, is this possible?
> SQL_Variant ... nope.
> Yes, C#, but really.
> Josh
>sql

Boolean datatype in SQLServer 2005?

I thought there was one at long, long last, but I don't see it!
Good grief, is this possible?
SQL_Variant ... nope.
Yes, C#, but really.
JoshHi Josh,
What's wrong with the bit type. It's been there for ever
kind regards
Greg O
--
Looking to use CLR in SQL 2005. Try some pre-build CLR Functions and SP
AGS SQL 2005 Utilities, over 20+ functions
http://www.ag-software.com/?tabid=38
"jxstern" <jxstern@.nowhere.xyz> wrote in message
news:lit3q1pom5csn3lmf8m1vvq1aelqm15f4n@.4ax.com...
>I thought there was one at long, long last, but I don't see it!
> Good grief, is this possible?
> SQL_Variant ... nope.
> Yes, C#, but really.
> Josh
>

Thursday, March 22, 2012

Book recommendations?

I do software support for software that works with both Oracle and SQL
Server, so I mostly just write queries to look at the data related to
the software. When I first started, I bought a couple of books to learn
the basics, intentionally going with generic books that would help with
both types of databases. I've got the basics down, and now I'm looking
for a really detailed reference book that goes really indepth into
querying for SQL Server specifically. Currently, we only work with the
2000 version, but we'll be going to 2005 soon, so I think I'd rather go
with a book on 2005, although if you know one that covers the
differences between them, that would be great. Any recommendations?

Besides just writing queries, I'd also like to learn more about SQL
Server in general. DBA software support, so I'd like to head my
career in that direction. I was looking at Microsoft's new
certification path for SQL 2005. Given that my company won't pay to
send me for training, and I really don't want to have to put down
$2200+ to pay for a class, I was thinking that I might be able to learn
enough on my own to pass the first test and get the MCTS title. I
ordered the Training Kit from Microsoft Press for that, which comes
with a 180 day trial of SQL Server 2005 to play with, along with a huge
book. Does anyone have any other recommendations for resources to help
learn this stuff?

--Richardblueghost73@.yahoo.com (blueghost73@.yahoo.com) writes:

Quote:

Originally Posted by

I do software support for software that works with both Oracle and SQL
Server, so I mostly just write queries to look at the data related to
the software. When I first started, I bought a couple of books to learn
the basics, intentionally going with generic books that would help with
both types of databases. I've got the basics down, and now I'm looking
for a really detailed reference book that goes really indepth into
querying for SQL Server specifically. Currently, we only work with the
2000 version, but we'll be going to 2005 soon, so I think I'd rather go
with a book on 2005, although if you know one that covers the
differences between them, that would be great. Any recommendations?


The ultimate book on writing queries on SQL 2005 simply must be "Inside
T-SQL Querying" by Itzik Ben-Gan on Microsoft Press. If there is a problem
he can't write a query for, then there is simple is no query to write - or
the query is not worth writing. I'm just about to read the book myself,
so I cannot say how much he compares with SQL 2000.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||According to Amazon, Ken Henderson is not even planning to release a
book about 2005 yet. What a pity.|||Erland Sommarskog wrote:

Quote:

Originally Posted by

>
The ultimate book on writing queries on SQL 2005 simply must be "Inside
T-SQL Querying" by Itzik Ben-Gan on Microsoft Press.


Here's a link to the book:
http://www.microsoft.com/MSPress/books/9615.asp
and the actual title is:
"Inside Microsoft SQL Server 2005: T-SQL Querying"|||metaperl wrote:

Quote:

Originally Posted by

Erland Sommarskog wrote:
>

Quote:

Originally Posted by


The ultimate book on writing queries on SQL 2005 simply must be "Inside
T-SQL Querying" by Itzik Ben-Gan on Microsoft Press.


>
Here's a link to the book:
http://www.microsoft.com/MSPress/books/9615.asp
>
and the actual title is:
"Inside Microsoft SQL Server 2005: T-SQL Querying"


So apparently, there's a consensus that this is THE book for T-SQL.
That's just odd. I've been using Usenet for 15 years, and I've never
seen an agreement before. Where's the usual flame war? :P

In looking into this book, I noticed that the author posted some
comments on amazon.com that the rest of you might be interested in.
Here they are:

--
FAQ - what's the difference between the two books ("T-SQL Querying" and
"T-SQL Programming")?

I often get this question, so I'll use this opportunity to clarify
things.

The original intention was to cover T-SQL Querying and Programming in
one book, but we realized that it would end up with 1,200 - 1,300
pages. So we decided to split the content into two books. You can think
of T-SQL Querying as Volume 1 and of T-SQL Programming as Volume 2.

T-SQL Querying focuses on querying and query tuning/optimization.
T-SQL Programming focuses on programmatic constructs (T-SQL and CLR
routines, XML, Service Broker, Dynamic SQL, Cursors, etc.).

Make sure you read T-SQL Querying before T-SQL Programming.

Here's the TOC for T-SQL Querying:
Chapter 01 - Logical Query Processing
Chapter 02 - Physical Query Processing
Chapter 03 - Query Tuning
Chapter 04 - Subqueries, Table Expressions and Ranking Functions
Chapter 05 - Joins and Set Operations
Chapter 06 - Aggregating and Pivoting Data
Chapter 07 - TOP and APPLY
Chapter 08 - Data Modification
Chapter 09 - Graphs, Trees, Hierarchies and Recursive Queries
Appendix A - Logic Puzzles

And here's the TOC for T-SQL Programming:
Chapter 01 - Datatype Related Problems, XML, and CLR UDTs
Chapter 02 - Temporary Tables and Table Variables
Chapter 03 - Cursors
Chapter 04 - Dynamic SQL
Chapter 05 - Views

T-SQL and CLR Routines:
Chapter 06 - User Defined Functions
Chapter 07 - Stored Procedures
Chapter 08 - Triggers

Chapter 09 - Transactions
Chapter 10 - Exception Handling
Chapter 11 - Service Broker
Appendix A - Companion to CLR Routines

Let me know if you have any questions.

Itzik
--
Hi all,

You can find detailed info about the book at www.insidetsql.com
including: TOC, Sample Chapters (just uploaded), Source Code, Links to
Related Resources, Corrections, Letter to the Reader, Author BIOs.
Please let me know if the organization of the website is convenient for
you or if you think that some things should be changed/added. Also, I'd
be glad to get any comments/questions regarding the book. You can
contact me through the website or through
itzik@.solidqualitylearning.com.

Cheers,
Itzik
--sql

Tuesday, March 20, 2012

Book contrasting Oracle and MS SQLServer?

I am an oracle savvy developer looking to switch to SS. Know of any
good books that compare/contrast the two?
Thankswaterlogged@.cfl.rr.com wrote:
> I am an oracle savvy developer looking to switch to SS. Know of any
> good books that compare/contrast the two?
> Thanks

If you've decided to switch then why compare?

>From the SQL development perspective take a look at O'Reilly's "SQL in
a Nutshell" (Kline and Kline).

Also take a look at these resources:
http://www.microsoft.com/sql/soluti...on/default.mspx

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/...US,SQL.90).aspx
--|||waterlogged@.cfl.rr.com wrote:
> I am an oracle savvy developer looking to switch to SS. Know of any
> good books that compare/contrast the two?
> Thanks

Try the following:

http://www.microsoft.com/sql/prodin...cle/oracle.mspx

http://www.microsoft.com/technet/pr...1.mspx?mfr=true

HTH,
Brian

--
================================================== =================

Brian Peasland
oracle_dba@.nospam.peasland.net
http://www.peasland.net

Remove the "nospam." from the email address to email me.

"I can give it to you cheap, quick, and good.
Now pick two out of the three" - Unknown|||waterlogged@.cfl.rr.com wrote:
> I am an oracle savvy developer looking to switch to SS. Know of any
> good books that compare/contrast the two?
> Thanks

Here's a website that does a detailed comparison:

http://dev.mysql.com/tech-resources...php?advanced=1

BOL Quote: "Two Merge Replication Proceses..."

Hi everyone,
I was hoping someone could offer some insight into a quote from the SQL
Server Compact 3.5 BOL
(ms-help://MS.SSC.v35/MS.SSC.v35.EN/sscmain/html/7434b4c1-5099-4d83-b5f9-75a9e6e72faa.htm):
"You cannot start two merge replication processes at the same time on the
same database."
I'm not sure what "same database" means. Is it referring to the same server
database? Let's say I have a sales force where SQL Compact 3.5 installed on
each agent's laptop. Does it mean only one sales agent at a time can merge
with the corporate server? Please tell me this is not true. We need to have
multiple agents replicating simultaneously.
Thanks very much.
Tom Baxter
Hello Tom,
I understand that you are confused by the descriptioin "You cannot start
two merge replication processes at the same time on the same database." in
BOL. You'd like to know only one sales agent at a time can merge with the
corporate server if you use merge replication.
I believe it's not true. You could have multiple agents replicate
simultaneously though there is only process running for the specific
database you'd like to replciate.
If you have any further concerns, please feel free to let's know.
Best Regards,
Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications
<http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx>.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
<http://msdn.microsoft.com/subscriptions/support/default.aspx>.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Wednesday, March 7, 2012

Blocked transactions - how to identify the sql commands?

Hi SQLServer gurus :)

Just wondering if anyone can give me some info on how to find out the full syntax of the commands executed by the blocked and blocking SPID's in a locking situation.

Using sp_who or sp_who2 will give basic info on the blocked trans (such as DELETE, SELECT etc), but not the actual statement. The blocking spid's command is only showing AWAITING COMMAND.

Not really an urgent problem, but any suggestions appreciated!

Cheers,
MeganDBCC INPUTBUFFER
Displays the last statement sent from a client to Microsoft SQL Server.

Syntax
DBCC INPUTBUFFER (spid)

You can use this command to see what is the longest running command which may point to the transaction that is causing the blocking.

DBCC OPENTRAN
Displays information about the oldest active transaction and the oldest distributed and nondistributed replicated transactions, if any, within the specified database. Results are displayed only if there is an active transaction or if the database contains replication information. An informational message is displayed if there are no active transactions.

Syntax
DBCC OPENTRAN
( { 'database_name' | database_id} )
[ WITH TABLERESULTS
[ , NO_INFOMSGS ]
]|||Thanks for your response, achorozy.

Friday, February 10, 2012

BitArray to binary

I want to store a binary string in SqlServer from VB .NET through a
stored procedure. I have been storing the binary data in a BitArray
which I am not set on by any means. When I pass the BitArray into a
stored procedure, which is looking for a variable of type binary, it
throws the following: "Object must implement IConvertible." BitArray
obviously does not implement IConvertable.

If anyone has a good way of passing binary data into a stored
procedure through a parameter array I'd appreciate it."Ramzi Abboud" <ramziabb@.gmail.com> wrote in message
news:a5617e65.0410141217.21e48d0@.posting.google.co m...
>I want to store a binary string in SqlServer from VB .NET through a
> stored procedure. I have been storing the binary data in a BitArray
> which I am not set on by any means. When I pass the BitArray into a
> stored procedure, which is looking for a variable of type binary, it
> throws the following: "Object must implement IConvertible." BitArray
> obviously does not implement IConvertable.
> If anyone has a good way of passing binary data into a stored
> procedure through a parameter array I'd appreciate it.

You might get a better answer by posting in a .NET or VB group. I don't know
what a BitArray is, but you can use the ADO Command object to execute stored
procedures with correctly typed parameters, which might be another
possiblity for you.

Simon