3

i want to get a string like [www.myweb.com?q=id%3D123456%26action%3Dgo​]

but actually i get [www.myweb.com?q=id%3D123456%26action%3Dgo?​]

It ends up with a question mark.

My data engine is SQL server 2012

declare @id bigint;
set @id=123456;

select 
'www.myweb.com?q=id%3D'+convert(varchar(20),@id) +'%26action%3Dgo​' 

enter image description here

Benny Ae
  • 1,897
  • 7
  • 25
  • 37
  • copy and paste above code to notepad. put cursor between D and g at end near %3Dgo. now press right arrow key once. went to between g and o? right arrow again... o and '... one more time should be to right of ' now right? but it's not.... right arrow again... now it its... you have a hidden character there that needs to be removed. Delete and retype the `%3Dgo'` – xQbert May 28 '15 at 18:49
  • your plan works , thanks a lot! – Benny Ae May 28 '15 at 18:53
  • 1
    The `?` appears because it contains a [Zero-Width Space](http://en.wikipedia.org/wiki/Zero-width_space). While your text editors support the character, the default character collation/encoding in SQL does not. The `?` is the substitute for "invalid" character data. Using natural string literals -- `N'www.myweb...go'` -- will allow SQL to support it. – Jonathan Lonowski May 28 '15 at 18:54
  • Just be sure to accept @sachu response. he put you on the right track, I just clarified his answer. and Jonathan Lonowski explains why well! – xQbert May 28 '15 at 18:54
  • @xQbert and Jonathan Lonowski well done mates..me too learned something new. – Sachu May 28 '15 at 18:58

1 Answers1

4

if you check by pasting the

 'www.myweb.com?q=id%3D'+convert(varchar(20),@id) +'%26action%3go​'

in sql server query window you can see a non-dsplay character between go and ' remove that run the query. the question mark will go

result

Community
  • 1
  • 1
Sachu
  • 7,555
  • 7
  • 55
  • 94