Solved

Need help formating tsql output

Posted on 2014-01-24
6
312 Views
Last Modified: 2014-01-25
I have the following sql statement:

SELECT TOP(4) ('arrDeck['), (HandRank),+ ',0] = "',(Cards),'"'
FROM HMHoleRankings

It returns:

               HandRank                 Cards
arrDeck[      1      ,0] = "      aa              "
arrDeck[      2      ,0] = "      kk              "
arrDeck[      3      ,0] = "      qq              "
arrDeck[      4      ,0] = "      aks             "

Needs to return:

arrDeck[1      ,0] = "aa"
arrDeck[2      ,0] = "kk"
arrDeck[3      ,0] = "qq"
arrDeck[4      ,0] = "aks"

What should I change to trim the values?

HandRank is an integer that needs to be returned as a character string.

Thanks,
0
Comment
Question by:Dovberman
  • 4
  • 2
6 Comments
 

Author Comment

by:Dovberman
ID: 39808329
Sorry,
Needs to return:

arrDeck[1,0] = "aa"
arrDeck[2,0] = "kk"
arrDeck[3,0] = "qq"
arrDeck[4,0] = "aks"
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 400 total points
ID: 39808503
Try this:
SELECT TOP(4) 'arrDeck[' + convert(varchar, HandRank) + ',0] = "' + (Cards) + '"'
FROM HMHoleRankings

Open in new window

0
 

Author Comment

by:Dovberman
ID: 39808640
Great improvement.

arrDeck[1,0] = "aa        "
arrDeck[2,0] = "kk        "
arrDeck[3,0] = "qq        "
arrDeck[4,0] = "aks       "

How do I eliminate the remaining blanks to return as follows?

arrDeck[1,0] = "aa"
arrDeck[2,0] = "kk"
arrDeck[3,0] = "qq"
arrDeck[4,0] = "aks"

Thanks,
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39808642
probably a char field instead of varchar, use
RTRIM(Cards)

Open in new window

0
 

Author Comment

by:Dovberman
ID: 39808663
Works perfectly.

Thanks
0
 

Author Closing Comment

by:Dovberman
ID: 39808665
Works perfectly.

Thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Slow Connectivity over ODBC 8 32
Sql server function help 15 28
TSQL - How to declare table name 26 29
How to search for strings inside db views 4 25
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question