Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9200679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:49:17+00:00 2026-06-17T22:49:17+00:00

I want to get all the fields from the table which i select in

  • 0

I want to get all the fields from the table which i select in the query even if the fields contains no value(the value null or empty). the following is the query i have written.

SELECT (
           SELECT T1.[CarrierCode_Destination] AS '@CarrierCode_Destination',
                  T1.[CarrierCode_Destination_Address] AS 
                  '@CarrierCode_Destination_Address',
                  T1.[CarrierCode_Destination_Address1] AS 
                  '@CarrierCode_Destination_Address1',
                  T1.[CarrierCode_Destination_Address2] AS 
                  '@CarrierCode_Destination_Address2',
                  T1.[CIMtrek_RegContact] AS '@CIMtrek_RegContact',
                  T1.[CIMtrek_CarrierContact] AS '@CIMtrek_CarrierContact',
                  [T1].[CIMtrek_AdditionalContacts] AS 
                  '@CIMtrek_AdditionalContacts'
           FROM   (
                      SELECT CD.[CIMtrek_DestinationName] 
                             CarrierCode_Destination,
                             CD.[CIMtrek_DestinationAdd] 
                             CarrierCode_Destination_Address,
                             CD.[CIMtrek_DestinationAdd_1] 
                             CarrierCode_Destination_Address1,
                             CD.[CIMtrek_DestinationAdd_2] 
                             CarrierCode_Destination_Address2,
                             CD.[CIMtrek_RegContact] CIMtrek_RegContact,
                             CD.[CIMtrek_CarrierContact] CIMtrek_CarrierContact,
                             CD.[CIMtrek_AdditionalContacts] 
                             CIMtrek_AdditionalContacts
                      FROM   CIMtrek_SystemTable_DatawareHouse CD
                      WHERE  LEN(
                                 LTRIM(
                                     RTRIM(ISNULL(LTRIM(RTRIM(CD.[CIMtrek_DestinationName])), ''))
                                 )
                             ) != 0
                  ) AS T1 
                  FOR XML PATH('Record'),
                  TYPE
       ) FOR XML PATH('CarrierCode_Destination'),
       TYPE

the results i get is

<CarrierCode_Destination>
  <Record CarrierCode_Destination="8S - San Fran" CarrierCode_Destination_Address="SAN FRANCISCO  -  Redistribution" CarrierCode_Destination_Address1="4025 Whipple Road, " CarrierCode_Destination_Address2="Union City CA  94587" CIMtrek_RegContact="RDC San Francisco" />
  <Record CarrierCode_Destination="8G - St Louis" CarrierCode_Destination_Address="ST. LOUIS  -  Redistribution" CarrierCode_Destination_Address1="126 Enterprise  Drive, " CarrierCode_Destination_Address2="Wentzville MO  63385" CIMtrek_RegContact="RDC St Louis" />
  <Record CarrierCode_Destination="V8     PHO/CYPR/CUST/TL  " />
</CarrierCode_Destination>

but i want all the fields which are selected in the query. If you see the result it gives me the fields which are having value and omits the fields which don’t have values.

how to do this, Please help.

Best Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:49:18+00:00Added an answer on June 17, 2026 at 10:49 pm

    If you use isnull() statements for each column you are selecting and convert null values to empty strings it should force the attributes to be generated for all columns. You may or may not also need to add rtrim() statements like I show below depending on if you have a datatype that is going to return a fixed size string:

    SELECT (
           SELECT rtrim(isnull(T1.[CarrierCode_Destination],'')) AS '@CarrierCode_Destination',
                  rtrim(isnull(T1.[CarrierCode_Destination_Address],'')) AS 
                  '@CarrierCode_Destination_Address',
                  rtrim(IsNull(T1.[CarrierCode_Destination_Address1],'')) AS 
                  '@CarrierCode_Destination_Address1',
                  rtrim(IsNull(T1.[CarrierCode_Destination_Address2],'')) AS 
                  '@CarrierCode_Destination_Address2',
                  rtrim(IsNull(T1.[CIMtrek_RegContact],'')) AS '@CIMtrek_RegContact',
                  rtrim(IsNull(T1.[CIMtrek_CarrierContact],'')) AS '@CIMtrek_CarrierContact',
                  rtrim(IsNull([T1].[CIMtrek_AdditionalContacts],'')) AS 
                  '@CIMtrek_AdditionalContacts'
           FROM   (
                      SELECT CD.[CIMtrek_DestinationName] 
                             CarrierCode_Destination,
                             CD.[CIMtrek_DestinationAdd] 
                             CarrierCode_Destination_Address,
                             CD.[CIMtrek_DestinationAdd_1] 
                             CarrierCode_Destination_Address1,
                             CD.[CIMtrek_DestinationAdd_2] 
                             CarrierCode_Destination_Address2,
                             CD.[CIMtrek_RegContact] CIMtrek_RegContact,
                             CD.[CIMtrek_CarrierContact] CIMtrek_CarrierContact,
                             CD.[CIMtrek_AdditionalContacts] 
                             CIMtrek_AdditionalContacts
                      FROM   CIMtrek_SystemTable_DatawareHouse CD
                      WHERE  LEN(
                                 LTRIM(
                                     RTRIM(ISNULL(LTRIM(RTRIM(CD.[CIMtrek_DestinationName])), ''))
                                 )
                             ) != 0
                  ) AS T1 
                  FOR XML PATH('Record'),
                  TYPE
       ) FOR XML PATH('CarrierCode_Destination'),
       TYPE
    

    That worked for me when I tested it out but if you are also having issues with empty values not generating attributes you can first force all the empty values to be returned as NULL from the select against your original data table using NULLIF()

    SELECT (
           SELECT rtrim(isnull(T1.[CarrierCode_Destination],'')) AS '@CarrierCode_Destination',
                  rtrim(isnull(T1.[CarrierCode_Destination_Address],'')) AS 
                  '@CarrierCode_Destination_Address',
                  rtrim(IsNull(T1.[CarrierCode_Destination_Address1],'')) AS 
                  '@CarrierCode_Destination_Address1',
                  rtrim(IsNull(T1.[CarrierCode_Destination_Address2],'')) AS 
                  '@CarrierCode_Destination_Address2',
                  rtrim(IsNull(T1.[CIMtrek_RegContact],'')) AS '@CIMtrek_RegContact',
                  rtrim(IsNull(T1.[CIMtrek_CarrierContact],'')) AS '@CIMtrek_CarrierContact',
                  rtrim(IsNull([T1].[CIMtrek_AdditionalContacts],'')) AS 
                  '@CIMtrek_AdditionalContacts'
           FROM   (
                      SELECT NullIF(CD.[CIMtrek_DestinationName],'') 
                             CarrierCode_Destination,
                             NullIF(CD.[CIMtrek_DestinationAdd],'') 
                             CarrierCode_Destination_Address,
                             NullIF(CD.[CIMtrek_DestinationAdd_1],'') 
                             CarrierCode_Destination_Address1,
                             NullIF(CD.[CIMtrek_DestinationAdd_2],'') 
                             CarrierCode_Destination_Address2,
                             NullIF(CD.[CIMtrek_RegContact],'') CIMtrek_RegContact,
                             NullIF(CD.[CIMtrek_CarrierContact],'') CIMtrek_CarrierContact,
                             NullIF(CD.[CIMtrek_AdditionalContacts],'') 
                             CIMtrek_AdditionalContacts
                      FROM   CIMtrek_SystemTable_DatawareHouse CD
                      WHERE  LEN(
                                 LTRIM(
                                     RTRIM(ISNULL(LTRIM(RTRIM(CD.[CIMtrek_DestinationName])), ''))
                                 )
                             ) != 0
                  ) AS T1 
                  FOR XML PATH('Record'),
                  TYPE
       ) FOR XML PATH('CarrierCode_Destination'),
       TYPE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which contains the following columns: UniqueID remote_ip_addr platform I want
I have a MySQL table which contains the following two fields (There are others,
i want query a file xml with linq, i want get all descendat of
I want to get all the Calendars, which are in my GoogleAccount, using the
I want to get all characters until there is an uppercase but from the
I have a table in my sqlite3 databse which has the following fields: id
I want to get the value on a table 2 for Keys on table
If I want to get a customer's email address from a database, the following
I have the following query: $select = $this->getDao()->select() ->from( array(new Zend_Db_Expr('FROM_UNIXTIME(expiration)')) ); The getDao
I cannot seem to get this MySQL query right. My table contains yearly inventory

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.