Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Passed Variable to Longer String Variable

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
This is probably very simple. I have a stored procedure where I am passingin a vendor ID that is 6 characters long. In the procedure I also need to use this same ID as a 10 character string. I don't want to pass in both of the values since they are the same except for length. Is it as simple as?
Code:
@VendID6 char(6),
@VendID10 char(10) = @VendID6
Or do I need to cast/convert/select the @VendID6 to @VendID10? Looking for the proper way to do this.

Auguy
Sylvania/Toledo Ohio
 
6 fits in 10 so why would you need to differentiate between the two? Do you need to add something to it to make it 10?

Simi
 
I guess it depends on how you plan on doing this. Personally, I wouldn't pass both parameters if they are ALWAYS going to be the same. Pass just one parameter and then declare another inside the procedure, like this:

Code:
Create Procedure TestParameters(@VendID6 char(6))
AS
SET NOCOUNT ON

Declare @VendID10 Char(10)
Set @VendID10 = @VendID6

Select @VendID6,@VendID10
go
Exec TestParameters 'ABCDEF'
go
Drop Procedure TestParameters

You should know that char variables are padded with spaces on the end of the data, so ABCDEF as a char(10) will be ABCDEF(space)(space)(space)(space).



-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
No change needed. Moving UP will be fine, it's moving DOWN that you run into issues. I would however, recommend using
Code:
DECLARE @VendID10 [COLOR=blue]VARCHAR[/color](10); 
SET @VendID10 = @VendID6;

--------------------------------------------------
Stubbornness is a virtue -- if you are right. --Chuck Noll
--------------------------------------------------
 
I'm updating two diferent databases where one table has the VendID as char(6) and the other as VendID char(10). I want to make sure the procedure matches the ID's correctly and I am worried about matching the 6 cahr to the 10 char column without adding the extra 4 spaces. Is it as simple as?
Code:
@VendID10 char(10) = @VendID6 + '    '


Auguy
Sylvania/Toledo Ohio
 
The CHAR will add the padding as needed. You will not need to worry about it.

--------------------------------------------------
Stubbornness is a virtue -- if you are right. --Chuck Noll
--------------------------------------------------
 
Thanks to all for your quick responses.

Auguy
Sylvania/Toledo Ohio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top