|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, December 12, 2012 8:04 AM
Points: 297,
Visits: 354
|
|
pretty basic so appreciate the help here,getting conversion error , what is the way to have int variable in the string?
declare @abc int set @abc =1 declare @cmd varchar(100)
select @cmd='select'+@abc+'hello' print @cmd
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Sunday, May 05, 2013 7:23 PM
Points: 133,
Visits: 1,060
|
|
This is what i do with my dynamic sql.
CONVERT(varchar(20),@abc)
so it would be
declare @abc int set @abc =1 declare @cmd varchar(100)
select @cmd='select'+CONVERT(varchar(20),@abc)+'hello' print @cmd
just remember to change varchar(20) to something sensible for your data
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, December 12, 2012 8:04 AM
Points: 297,
Visits: 354
|
|
thank you , i was trying to use cast but that did not working , thanks again
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Sunday, May 05, 2013 7:23 PM
Points: 133,
Visits: 1,060
|
|
This was my first answered question so thank you
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Tuesday, January 15, 2013 11:11 AM
Points: 1,945,
Visits: 2,782
|
|
I was trying to use cast but that did not working , thanks again
CAST(@abc AS VARCHAR(10)) should work and it much preferred over the old 1970's Sybase CONVERT string function. What did you write?
The real question is why do you want to change a numeric to a string anyway? This is usually a sign of a COBOL mindset that is trying to format data in the database for display.
Books in Celko Series for Morgan-Kaufmann Publishing Analytics and OLAP in SQL Data and Databases: Concepts in Practice Data, Measurements and Standards in SQL SQL for Smarties SQL Programming Style SQL Puzzles and Answers Thinking in Sets Trees and Hierarchies in SQL
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 10:59 AM
Points: 2,525,
Visits: 4,324
|
|
CELKO (11/25/2012)
... CAST(@abc AS VARCHAR(10)) should work and it much preferred over the old 1970's Sybase CONVERT string function...
CAST and CONVERT are similar but not the same. CAST in T-SQL offers limited (basic) data conversion functionality. I cannot see why someone would prefer one over another... It's not matter of preference, it is matter of suitability. Where CAST functionality is sufficient, you use CAST, where it's not enough (requires specific format key/switch) - use CONVERT. For example, (especially for standards-loving J.C.) using CAST you can not explicitly convert DATETIME into string in ISO format...
_____________________________________________ "The only true wisdom is in knowing you know nothing" "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!" (So many miracle inventions provided by MS to us...)
How to post your question to get the best and quick help
|
|
|
|