Solved

Access vs. SQL bit datatype  linked table

Posted on 2002-04-23
8
217 Views
Last Modified: 2008-03-17
I have a linked table in Access 2000 which is linked to a SQL table which has a bit datatype field called [FIELDBIT].
I want to pass this bit to a stored procedure call mysp using a pass-through qry as such:

sp_SQL = "EXECUTE mysp " & _
 "'" & arg1 & "'," & _
 "'" & arg2 & "'," & rs![FIELDBIT]
   
The value of rs!FIELDBIT is not 1 or 0(as it would be in sql) but True and False. So my pass-through qry translates to this:
EXECUTE mysp arg1,arg2, TRUE

SQL balks, converting nvarchar to bit. SQL would prefer this:
EXECUTE mysp arg1,arg2, 1

I know how to code a work-around. Abs(CInt(rs![FIELDBIT]))
My question is how to call the sp without a workaround?

0
Comment
Question by:Paullkha
8 Comments
 
LVL 8

Accepted Solution

by:
dovholuk earned 50 total points
ID: 6963066
there is no workaround.

you could experiment with creating a user-defined data type or something like that, but there's no need.  

instead of using true/false, you could change your check box to on/off. that should fix your issue too...

another point of interest (maybe), ANY number you send to SQL Server will be translated as true, so you shouldn't need to use the ABS() method in your example.

another "workaround" that's not as efficient as the one you already use, is to pass the argument as a string, then use the stored procedure to "validate" the string... although i don't see this as being a good idea at all... something like:

if @TrueOrFalse = 'FALSE'
   set @SomeOtherTrueOrFalseVariable = 0
else
   set @SomeOtherTrueOrFalseVariable = 1

*shrug* i think the "workaround" you're using now is the best method available...

good luck.

dovholuk
0
 
LVL 8

Expert Comment

by:dovholuk
ID: 6963068
as a side note, you have a few outstanding questions in other areas... you should try to clear these up.

help keep our EE "clean"

thanks,

dovholuk
0
 
LVL 5

Expert Comment

by:spcmnspff
ID: 6963241
SQL Server implicitly coverts from NVarChar to Bit or integer to bit.  Bit is actually quite flexible.  If you try to update a bit field to anything other than 0 then the field becomes 1 (or on).  So the way I see it, you can code a workaround if you change the last parameter in your proc to a Int.  

Create Proc MySP
    @Arg1 VarChar(50),
    @Arg2 VarChar(50),
    @IntValue Int
AS

Now, with your quotes arranged the way they are, your string sp_sql in vb looks like this:

EXECUTE mysp 'arg1','arg2', -1

(The value true in vb is the integer value -1.)

So say you do an insert statement in you proc:

Insert Into MyTbl
(Arg1, Arg2, BitField)
Values @Arg1, @Arg2, @IntValue

Into the following table . . .

Create Table MyTbl
 Arg1 VarChar(50),
 Arg2 VarChar(50),
 BitField Bit

SQL Server will automatically do the following interpretation for the bit field:
                    0 - 0
Anything Other Than 0 - 1

Of course this would also work for an update statement.
=)                
0
 
LVL 32

Expert Comment

by:bhess1
ID: 6963324
You can use your local engine to pass the correct data.  Use the IIF function:

sp_SQL = "EXECUTE mysp " & _
"'" & arg1 & "'," & _
"'" & arg2 & "'," & iif(rs![FIELDBIT],1,0)

This will pass 1 if True and 0 If not
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 1

Expert Comment

by:Moondancer
ID: 6979371
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20292692.html
http://www.experts-exchange.com/questions/Q.20255048.html
http://www.experts-exchange.com/questions/Q.20284498.html
http://www.experts-exchange.com/questions/Q.20284957.html
http://www.experts-exchange.com/questions/Q.20293564.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20089266.html

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0
 
LVL 8

Expert Comment

by:dovholuk
ID: 6979503
i think it's good info.

i'd say (humbily sp) to accept dovholuk comment as answer.

dovholuk
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6981283
Thank you, finalized today.
Moondancer - EE Moderator
0
 
LVL 2

Author Comment

by:Paullkha
ID: 6983623
Seven days turnaround, damn, this is new. I do apologize.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now