connection string in SQL Server

Hi Guys,

I have this query in my SQL Server:

 
set @connectionstring1  = '
declare @txtOutput varchar(50);
EXEC OPENDATASOURCE(''SQLOLEDB'', ''Data Source=' + @servername 
+ ';User ID=' + @userr +  ';Password=' + @paswerd + ''').[' + @dbname +  '].[dbo].[sp_web_updcustNew]  '''+ @txtMobileNoOld + ''', '''+ @txtMobileNoNew + ''', '''+ @txtPSTNOld + ''', '''+ @txtPSTNNew + ''', '''+ @txtFirstName + ''', '''+ @txtLastName + ''', '''+@dtBirthDate+''', '''+ @txtJenisKelamin + ''', '''+ @txtAlamat + ''', '''+@txtPropinsiID  + '', @txtKabKotaID , '''+ @txtEmailOld + ''', '''+ @txtEmailNew + ''', '''+ @txtWebSiteID + ''', '''+ @txtNoKTP + ''', '''+ @txtKontakID+ ''', '''+ @txtWebUID + ''', '''+ @txtPasswordNew + ''', @txtOutput output;insert into #myTempTable values(@txtOutput)'
exec (@connectionstring1);

Open in new window


The problem is, it's giving error because @txtMobileNoOld and @txtMobileNoNew is INT(integer), but that my code will send as '02143254435', it supposed to be 02143254435 (without single quote).

Please help changing my code, so the @txtMobileNoOld and @txtMobileNoNew  will be sent without single quote, and will still working properly.

Thanks.
softblessAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cyberkiwiCommented:
Well.. If it's an int, then there is not supposed to be any leading 0's?  You could remove the quotes

'''+ @txtMobileNoOld + ''', '''+ @txtMobileNoNew + '''

to

'+ @txtMobileNoOld + ', '+ @txtMobileNoNew + '

But that means it is now just a number, for which the leading 0 will have no meaning.
0
cyberkiwiCommented:
It looks like you might need to check inside sp_web_updcustNew

Because the right approach could be to send in the STRING, including leading 0, then have it handle properly (it should NOT end up with the enclosing quotes in the db)
0
Ephraim WangoyaCommented:

set @connectionstring1  = 
'declare @txtOutput varchar(50);
EXEC OPENDATASOURCE(''SQLOLEDB'', ''Data Source=' + @servername 
+ ';User ID=' + @userr +  ';Password=' + @paswerd + ''').[' + @dbname +  '].[dbo].[sp_web_updcustNew]  '+ @txtMobileNoOld + ', '+ @txtMobileNoNew + ', '''+ @txtPSTNOld + ''', '''+ @txtPSTNNew + ''', '''+ @txtFirstName + ''', '''+ @txtLastName + ''', '''+@dtBirthDate+''', '''+ @txtJenisKelamin + ''', '''+ @txtAlamat + ''', '''+@txtPropinsiID  + '', @txtKabKotaID , '''+ @txtEmailOld + ''', '''+ @txtEmailNew + ''', '''+ @txtWebSiteID + ''', '''+ @txtNoKTP + ''', '''+ @txtKontakID+ ''', '''+ @txtWebUID + ''', '''+ @txtPasswordNew + ''', @txtOutput output;insert into #myTempTable values(@txtOutput)'
exec (@connectionstring1);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
softblessAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.