Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQL Convert() Cast()

Author  Topic 

timsweet
Starting Member

31 Posts

Posted - 2005-08-19 : 11:35:32
1. This one of the best site to get and give assistance..Thanks

2.. I have a stored procedure and I need to convert a datatype of nvarchar to bit that a web page is passing (I know...WHY?...don't want to go there)

I was wonder which is best to use and where to use it and syntax.

This Stored Procedure calls two others here is apiece of it:
***********************************************************
CREATE Procedure sp_UpdContactSuper_web

@ABR_ID as nvarchar(5),
@OffPhoneExists as nvarchar(5),
@HomePhoneExists as nvarchar(5),
@FaxExists as nvarchar(5),
@CellPhoneExists as nvarchar(5),
@WorkEmailExists as nvarchar(5),
@HomeEmailExists as nvarchar(5),
@OffPhoneDetails as nvarchar(50),
@HomePhoneDetails as nvarchar(50),
@FaxDetails as nvarchar(50),
@CellPhoneDetails as nvarchar(50),
@WorkEmailDetails as nvarchar(50),
@HomeEmailDetails as nvarchar(50),
@OffPhonePC as nvarchar(1), -- bit,
@HomePhonePC as nvarchar(1), -- bit,
@FaxPC as nvarchar(1), -- bit,
@CellPhonePC as nvarchar(1), -- bit,
@WorkEmailPC as nvarchar(1), -- bit,
@HomeEmailPC as nvarchar(1), -- bit,
--@RecordUpdatedDate datetime,
@RecordUpdatedProcess nvarchar(25),
@RecordUpdatedUser nvarchar(25)


as
Declare @details as nvarchar(50)
Declare @PrimaryContact bit

If @OffPhoneExists = 1
set @details = @offPhoneDetails
set @PrimaryContact = @OffPhonePC
--Cast(@PrimaryContact) as bit
--Convert(@PrimaryContact) as bit


Begin


Execute sp_UpdCurrContact @abr_id, 'Office', @details, @Primarycontact, @RecordUpdatedUser
Execute sp_InsCurrContact @abr_id, 'Office', @details, @PrimaryContact, @RecordUpdatedUser
end
********************************************************************
Thanks in advance.

Tim

X002548
Not Just a Number

15586 Posts

Posted - 2005-08-19 : 12:42:59
Not that I want you to go there...but following the advice in the hint link...give us at keast some sample data

Oh, and CONVERT is CONVERT(bit,@x) and CAST is CAST(@x AS bit)

Your values had better be 0,1 or null



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-08-19 : 13:00:04
If I've got the wright end of the stick

set @PrimaryContact = @OffPhonePC
--Cast(@PrimaryContact) as bit
--Convert(@PrimaryContact) as bit

should be

SELECT @PrimaryContact = CAST(@OffPhonePC AS bit)

If I've got my facts right CAST is ANSI, CONVERT is T-SQL proprietory, thus CAST is probably "prefered"

Kristen
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-08-19 : 13:16:03
quote:
Originally posted by Kristen
If I've got my facts right CAST is ANSI, CONVERT is T-SQL proprietory, thus CAST is probably "prefered"

Kristen



No style points for you Kristen....

But you are correct sir!

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-08-19 : 13:48:30
CONVERT has more style does it?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-22 : 02:04:46
>>CONVERT has more style does it?

Yes it is
particularly for datetime

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-08-22 : 14:46:31
Go to Top of Page
   

- Advertisement -