June 29, 2011 at 11:20 pm
Hello Folks, I am trying to write a function. If input is like AAAA, pqrstuv, xxxx-lmn, ZZZsswD then output should be 'AAAA', PQRSTUV', 'XXX-LMN', 'ZZZSSWD'. Any suggestions ?
June 30, 2011 at 12:17 am
SQL Server has a built-in function to do this:
select UPPER('sql server')
Which will yield:
SQL SERVER
Thanks & Regards,
Nakul Vachhrajani.
http://nakulvachhrajani.com
Follow me on
Twitter: @sqltwins
June 30, 2011 at 12:39 am
Thanks Nakul. Thats not what I'm looking for. Lolz.
Actually looking for "If input string is like AAAA, pqrstuv, xxxx-lmn, ZZZsswD then output string should be 'AAAA', PQRSTUV', 'XXX-LMN', 'ZZZSSWD'".
June 30, 2011 at 2:04 am
sqlnaive (6/30/2011)
Thanks Nakul. Thats not what I'm looking for. Lolz.Actually looking for "If input string is like AAAA, pqrstuv, xxxx-lmn, ZZZsswD then output string should be 'AAAA', PQRSTUV', 'XXX-LMN', 'ZZZSSWD'".
The 'words' of the input string are unquoted, mixed-case and delimited.
The 'words' of the output string are upper-cased, mostly quoted, and delimited - and different: xxxx-lmn <> 'XXX-LMN'. What are you trying to do?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
June 30, 2011 at 3:46 am
I just want to input a string separated by comma and process it to give me output with same string separated by comma BUT having quoted each word so that i can put that string in the IN() query.
June 30, 2011 at 3:51 am
Like this?
DECLARE @string AS VARCHAR(50)
SET @string = 'AAAA, pqrstuv, xxxx-lmn, ZZZsswD'
SELECT '''' + REPLACE(REPLACE(UPPER(@string),' ',''),',',''',''') + ''''
-Edit-
Bear in mind that this will not work if there are ever spaces in the values in the string, e.g. "E ast, is, eAsy" would be translated to "'EAST','IS','EASY'"
June 30, 2011 at 4:16 am
yes, Perfect. Thats what I was looking for. Thanks once again.
June 30, 2011 at 10:05 am
If you want a more robust delimited string parser check out this article[/url] from Jeff Moden.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply