Alias a field name in a join query

I have a database with spaces in the field names (not my fault).
I am having a problem with the query because one of the fileds I am joining on has a space in its name. See bolded text.
SELECT *
FROM employee_passwords
INNER JOIN employee_general_info
ON employee_passwords.Employee_ID=employees.[Employee ID]
WHERE username = '#username#' AND password = '#password#'  
So I get this error message
Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Invalid object name 'employees.Employee ID'.
Is there a way to alias the employees.[Employee ID] field?

Should be
ON employee_passwords.Employee_ID=employee_general_info.[Employee ID]

Similar Messages

  • Alias with field name in MS SQL Server

    Is it possible that we can define alias for field name in MS SQL Server?
    For example:
    mytable : Id, Name, Value
    Could we define "AnotherName" for "Name" field that we can call it from sql
    SELECT anothername from mytable

    I don't know if you can "permanently" create an alias
    without a view or something like that but if you just
    want another name when you execute a select do this:
    Select name as another name from tableAt least in some databases the syntax for that can vary slightly. So the following might be needed....
    Select name as 'another name' from table

  • Problem using alias field names in a sql query

    Hello,
    I have a question regarding a simple Oracle database SQL query writeup:
    In the following (badly written but properly working) SQL query:
    Query 1:
    select
    soe.field1,
    (soe.field2 + soe.field3) as field4,
    (soe.field5 - (soe.field2 + soe.field3)) as field6,
    (select comp.parValue*soe.field7
    from
    CompTable comp) as parValue,
    (select soe.field8 - (comp.parValue*soe.field7+ soe.field9)
    from
    CompTable comp) as field10
    from
    SomeTable soe
    PROBLEM 1:
    I am re writing the code (soe.field2 + soe.field3) to get the alias field4 or column name field4 that I have created on the fly in the previously for use with the following fields. Can't I rewrite the query as follows. There is something simple missing!
    Query 2:
    select
    soe.field1,
    (soe.field2 + soe.field3) as field4,
    soe.field5 - field4 as field6, <<< field4 does not work here
    (select
    comp.parValue*soe.field7
    from
    CompTable comp) as parValue,
    (select
    soe.field8 - (comp.parValue*soe.field7+ soe.field9)
    from
    CompTable comp) as field10
    from
    SomeTable soe
    PROBLEM 2:
    Similar to the above problem, I was thinking to get a field parValue out of the CompTable table and re-use many times rather than the code shown in Query 1:
    Query 3:
    select
    soe.field1,
    (soe.field2 + soe.field3) as field4,
    soe.field5 - field4 as field6,
    soe.field7* (select comp.parValue from CompTable comp) as parValue1,
    soe.field8 - (parValue1*soe.field7+ soe.field9) as field10      <<<< parvalue1 does not work here
    parValue1*soe.field9 as TaxCondition               <<<< parvalue1 does not work here
    from
    SomeTable soe
    See that the query becomes so simple, but the above query does not work. There is something fundamentally wrong in my usage of the alias field names in creating other fields. The Query1 seems to be the only working option but its very slow as I am redoing and re-writing the whole code again and again to get the parValue field out of the CompTable table for use to create many other fields.
    I will appreciate if you can guide me in the right direction on this issue.
    Thanks and Regards
    Rama

    SELECT tmp.contract_no, tmp.Actual, tmp.Actual - tmp.NbHours
    FROM ( SELECT t.contract_no, sum(l.hrs) AS Actual, (c.labour_hours * c.labour_progress_per) / 100 AS NbHours
    FROM TASK_DELEGATION t
    INNER JOIN COST_CODE c
    ON t.cost_code = c.cost_code AND t.contract_no = c.contract_no AND t.is_inactive=0
    INNER JOIN Labour.dbo.LABOURALLOT l
    ON l.contractNo = c.contract_no AND l.costcode = c.cost_code AND l.pm = 'N'
    GROUP BY t.contract_no, c.labour_hours, c.labour_progress_per
    ) tmp

  • Deciphering column names in a join query using jdbc

    hi all....
    I am making a database adapter for a generic report generater. This adapter would be forming queries involing various tables. There are two ways of doing it . I fire an sql on parent table to get the keys and then go to child table for each one of them or i form a join query to get desired result.
    i want to go with the later approach where my query would be forming a join. The problem comes when table involved in this join has columns with the same name. for eg if a column "NOTE" is there in table A as well as table B on which i have a join. Resultset returns me with two "NOTE" columns and i cannot recognize which one belongs to which table.
    all API calls including getString("Note") seems to be referring to the first occurence of "Note" column.
    Also getTableName() and getSchemaName() APIs on resultsetMetadata doesnt return in anything in case of joins.
    Any pointers would be most appreciated.
    cheers
    vivek

    thanks for suggesting this solution ... though i had thought of the same onece .... unfortunately i cannot implement something like this coz out of the result set i have to instantiate an object hierarchy depending on the schema ....
    this also puts me in a doubt whether i can use join in my case.
    for eg ... .
    lets say we have a customer talbe and and address table which has one to many relationship .... one contact can have multiple addresses.
    Assuming a contanct "Joe Bloggs" having 3 addresses ...a query like following
    select contact.firstname contactfirstname , address.streetname addressstreetname from contact , address where contact.contactid = address.contactid
    this would return me 3 rows and i can also recognize various columns with their aliases ..
    but i would lose an important fact that i have to create one java object for contact class and 3 instances for addresses which i have to return finally.
    this means that i would like to return an object hierarchy with one contact object and 3 address object underneath it linked with contactid.
    Any other suggestions after reading the complete requirement are most welcome ...sorry for not puting the entire thing at first.
    i guess the only soln left is to visit contact and address table separately. :(

  • Output Technical Field Names in the SAP query Output

    Hi Experts,
    I am new to SAP Query/ABAP Query or Quick Viewer. Just would like to know if there is a way whereby I can print the technical field names as opposed to the English field headers. For example I want to print BUKRS in the place of CoCode.
    I have a vague feeling this could be possible through custom coding in SQ02 but have no idea which code section to choose.Any inputs greatly appreciated.
    thanks in advance,

    Hi Sreegopalan,
    Open your infoset in SQ02, by default in the left hand side you'll be having the tables that you have selected, double click the field name which you want change the long text, it will open a attributes window below your field group. Change the header data text as you wish.
    Please find the query documentation in the below link.
    [http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVQUE/BCSRVQUE.pdf]
    Regards,
    Nandha

  • Hash in database field name

    I have a field name that has a hash (#) symbol in the name. I
    have no control over the naming structure of this particular
    database. I need to output this field. How the heck do I do this? I
    know how if the output has a # in it, but what about the actual
    field name?
    Thanks,

    Your best bet is to alias the field name in SQL before you
    start dealing with your recordset in CF. You should be able to
    escape the hash using ## instead of #.
    If for some reason you can't alias the field name in your SQL
    statement, you can output query data in the following format:
    QueryName["FieldName"][RowNumber]
    I bet you can do something like this:
    qMyQuery["Hash##Field"][1]

  • Using variable with the same name as field name?

    I have a complex proc where I have variables with the same name as field name used on a query. something like this:
    SELECT a.id_table WHERE a.id_table = id_table
    where the last id_table is a parameter sent to the proc:
    declare procedure myproc(id_table int)
    Is there any way or notation to declare the variable inside the query as a variable or I have to use a different name?

    Well, variables are not the only thing you have to change if you want to switch to Oracle.
    Although I don't think it is good practice (to use variable name same as column name), here is one example how you can achieve it using EXECUTE IMMEDIATE and bind variable
    SQL> select deptno, count(1)
      2  from scott.emp
      3  group by deptno;
        DEPTNO   COUNT(1)
            30          6
            20          5
    10 3
    SQL> set serveroutput on
    SQL> declare
      2  deptno varchar2(10);
      3  i number;
      4  begin
      5  deptno:=10;
      6  execute immediate
      7  'select count(1) from scott.emp where deptno=:deptno' into i using deptno;
      8  dbms_output.put_line('OUT ---> '||i);
      9  end;
    10  /
    OUT ---> 3
    PL/SQL procedure successfully completed.
    SQL> Message was edited by:
    tekicora
    Message was edited by:
    tekicora

  • Alias for field in inner join query

    In my Oracle 9i Schema, I have two tables:TableOne
    pocOne    pocTwo
    2           3
    2           4
    1           2
    TableTwo
    TableTwoId   Name
    1            Jones
    2            Smith
    3            Edwards
    4            CamdenMy SQL that works to fetch all records with Smith works great:select Name from TableTwo
    Inner Join TableOne
    on TableTwo.TableTwoId in (TableOne.pocOne, TableOne.pocTwo)
    where Name = 'Smith' Now I need to create an alias for the Name field. Here is my attempt:select myAliasName from TableTwo
    Inner Join TableOne
    on TableTwo.TableTwoId in (TableOne.pocOne, TableOne.pocTwo), (select Name as myAliasName from TableTwo)
    where myAliasName = 'Smith' This attempt pulls up all the records instead of just Smith records. Please advise how I can create an alias for the Name field in my above query?

    Are you just looking for
    select Name AS AliasName
       from TableTwo Inner Join TableOne
              on TableTwo.TableTwoId in (TableOne.pocOne, TableOne.pocTwo)
    where Name = 'Smith' Justin

  • How to display the field name in the tabulated view for a content query web part

    I have added a content query web part changed the web part file to include custom columns imported and reffered itemstyle.xsl
    to include the tabulated view for the content query.
    However the way it is displayed is such that only the content is displayed.
    As i am using a tabular view wto display the data, i want to display their field names as well.

    Hi  ,
    According to your description, my understanding is that you need to display the field in the tabulated view for a content query web part.
    For your issue, please refer to the code as below:
    <xsl:template name="VendorCustomStyle" match="Row[@Style='VendorCustomStyle']" mode="itemstyle">
    <html>
    <table width="100%">
    <xsl:if test="count(preceding-sibling::*)=0">
    <tr>
    <td width="8%" valign="top"><div class="item"><b>Vendor ID</b></div></td>
    <td width="12%" valign="top"><div class="item"><b>Vendor Name</b></div></td>
    <td width="50%" valign="top"><div class="item"><b>Vendor Description</b></div></td>
    <td width="10%" valign="top"><div class="item"><b>Vendor Country</b></div></td>
    <td width="10%" valign="top"><div class="item"><b>Vendor Date</b></div></td>
    <td width="10%" valign="top"><div class="item"><b>Created By</b></div></td>
    </tr>
    </xsl:if>
    <tr>
    <td width="8%" valign="top"><div class="item"><xsl:value-of select="@VendorID" /></div></td>
    <td width="12%" valign="top"><div class="item"><xsl:value-of select="@Title" /></div></td>
    <td width="50%" valign="top"><div class="item"><xsl:value-of select="@Vendor_x005F_x0020_Description" disable-output-escaping="yes" /></div></td>
    <td width="10%" valign="top"><div class="item"><xsl:value-of select="@Vendor_x005F_x0020_Country" /></div></td>
    <td width="10%" valign="top"><div class="item"><xsl:value-of select="@Vendor_x005F_x0020_Date" /></div></td>
    <td width="10%" valign="top"><div class="item"><xsl:value-of select="@Author" /></div></td>
    </tr>
    </table>
    </html>
    </xsl:template>
    For more information, please have a look at the blog:
    http://www.codeproject.com/Articles/756834/Customizing-the-Content-Query-Web-Part-and-Item-St
    http://msdn.microsoft.com/en-us/library/ms497457.aspx
    http://clarksteveb.hubpages.com/hub/Customized-Content-Query-Web-Part-CQWP-in-SharePoint-2007-with-results-Tabbed-Grouped-and-in-an-HTML-Table
    http://blog.sharepointexperience.com/customitemstyle/
    Best Regards,
    Eric
    Eric Tao
    TechNet Community Support

  • Using field names stored in the database in a query

    Hi,
    I'm working on a database that has field names stored in tables. In order to construct a query using the field names stored in the table, normally I'd use dynamic SQL. 
    For example in table1 I have
    Field_Name Value
    Field1
    'Name'
    Field 2
           'Address'
    I want to build a select statement  "SELECT Name, Address, FROM tblCustTable" - if possible not using dynamic SQL.
    Is there a neat way to do this?
    Thanks very much.
    Sad old developer

    No, it is not possible to dynamically include ANY object names (Columns, Tables, Functions, Procedures, etc) in SQL without using Dynamic SQL.
    The closest you can get, if you are choosing from a known set of names, is to use CASE statements:
    SELECT CASE
    WHEN t1.Field1='Name' THEN ct.[Name]
    WHEN t1.Field1='Address' THEN ct.[Address]
    END AS Field1
    FROM tblCustTable ct
    CROSSJOIN table1 t1
    WHERE ...
    However there are several disadvantages to this approach, and the SQL will quickly get very convoluted and difficult to maintain.   Dynamic SQL is much cleaner.
    -Tab Alleman

  • Adding a field to rhe join query

    Dear Friends,
    I need your help in adding a field to a join query.
    I have created a reort using join(SQVI). Now i want to add an addition field to that report. The issue is the field i am looking at is stored in structure. Is there any way i can add this field....
    Sanjay

    It is not possible here (in SQVI).
    you have to Go with Query.
    SQ02 using this Create infoset, add all the tables , here include that structure field, and then add the logic to populate the field.
    Now go to SQ01 and create Query.

  • Cfoutput query and form field names

    I have a form that have two field inputs. I would like to repeat the form fields as part of a cfoutput query. The first field of the form automatically populates the different person's name (via cfoutput query) and this form field is called "tenant". The next field of the form is called "sales". The sales field is left open for user imput. The entire form is in between the cfoutput query tags. When the cfoutput query is executed, Both form fields of the form is displayed with each tenant name listed in each of the first form fields of each row. The problem I'm running into is that even though the form elements appear to display correctly, I would like the name of each of my form elements in the cfoutput query, of each row to have a different form field name like, tenant2, sales2, tenant3, sales3 etc. is that possible?
    Here's what my code look like.
    <cfform action= "addsales.cfm" method="post">
    <cfoutput query="tenantsales"><Input name="tenant" type="text" value="#office.tenant#" size="32" />
    <select name="sales"><option>$5</option><option>$10</option><option>$12</option></br></cfoutput>
    <input name="submit" type="submit" />
    </cfform>

    I cannot imagine why you would want to show a list of pre-populated input fields. What makes sense to me is a select-box. If that is indeed what you want, then you could do something like this:
    <cfform action= "addsales.cfm" method="post">
    <cfselect name="tenant">
        <option value="">Tenant</option>
    <cfoutput query="tenantsales">
        <option value="#tenantsales.tenantID#">#tenantsales.tenantName#</option>
    </cfoutput>
    </cfselect></br>
    <cfselect name="sales">
    <option value="">Sales</option>
    <option value="5">$5</option>
    <option value="10">$10</option>
    <option value="12">$12</option>
    </cfselect></br>
    <cfinput name="submit" type="submit" value="Submit" />
    </cfform>
    Like Dan, I have assumed your database table has a column for tenant ID.

  • Query Field names in Crystal

    In Crytal I see parameters but the database field names are the long name ie (0CCA_C11_ZNN_0CCA_C11_Q004.M[Measures].[8WEVD1XARY9RST55SBE42RTJD3VA0MBXNGQL9Y0JC76EALK4XU]C
    Can someone explain how to the user friendly name ?

    Hi,
    I assume that this field is pointing back to a keyfigure in the SAP BW Query.
    The Query Designer is offering you an option in the context menu to create a technical name for the keyfigure.
    As soon as you did that and after a "verify database" in Crystal Reports you will see these defined technical names in Crystal Reports
    Ingo Hilgefort
    Business Objects

  • Write a query for which has its field name as input parameter

    Hi All,
    I need to write a query for SSRS report. StartDate, EndDate and ChangedField are the input parameters.
    Let's consider that we are taking employee details. The table contains lot of fields like emp name,add1,add2,city,state,country,designation,rank etc. We have almost 30 fields are there. These field name are coming as input parameter "ChangedField"
    . I need to show the records which belong to the start date and end date also data change for the field which is given in the input parameter "ChangedField".  That meand If I give ChangedField="city", we need to check for data which
    has been updated with new City name in the given time period.
    Please suggest.
    Regards,
    Julie

    Hi Julie,
    Per my understanding that you have many fields in the table to be displayed in the report, some of the fields will always show and others should be hide and show based on the selection of the parameters which include the columns names, right?
    By default, we can't display columns dynamically in the report automatically without insert this column in the report before. So, in your scenario, I will suggest you to add all the columns in the reports first and then add show/hide expression on
    the column visibility based on the selection of the parameter "ChangedField", when some of the fields selectted they will be display, otherwise they will be hidden. For the fields which you want to be always displayed will not need to add the expression
    in the column visibility.
    Details steps about how to acheive this, please referencet to the  article below:
    Displaying Dynamic Columns in SSRS Report
    If you still have any problem, please feel free to ask.
    Regards,
    Vicky Liu
    Vicky Liu
    TechNet Community Support

  • Query field names renamed to Expr1

    I recently had things quit working in a newer Access database that has been stable for several months.&nbsp; I tracked it down to field names in the queries changed from a name to "Expr1".
    Behaved like this topic:
    https://social.msdn.microsoft.com/Forums/office/en-US/b92d559b-2ce3-4b37-9939-a2a519b3429b/upgrade-from-2003-to-2010-causing-query-column-name-problems?forum=accessdev
    It's in Access 2010 and I did not upgrade, and I did not change any linked tables.
    I'm wondering if it had anything to do when I did a Compact and Repair on the database.
    Per other articles I have unchecked ALL boxes under Access/Options/Current Database/Name AutoCorrect Options
    Thanks for any help you can provide!

    I had a backup copy so this morning I went through all the queries and found the Expr1 and changed them back.  I had no calculated fields, and I didn't change anything in the queries.  (I added a new and different query, but that was it. 
    Didn't touch any other queries, and this happened in all the other queries.)
    My main concern is not knowing what caused it, and preventing it from happening again.  I'm hoping removing the Name AutoCorrect prevents that.
    I appreciate the reply.  Thanks!

Maybe you are looking for

  • Address book entries vanished

    I was updating my address book and moving contacts into new groups when my entire list of contacts and all groups vanished. Spotlight does not reveal any vcards or contact files on the hard drive. A telephone call to technical support was not helpful

  • Float.NaN doesn't seem to work with appserver7

    I am in the process of upgrading an existing application that uses Float.NaN for invalid values when persisting to the database. I am upgrading from just using SQL statements to entity beans for the persistence layer. Is Float.NaN or Double.NaN not s

  • Regarding Webservice

    Hi Everyone,      Can we convert simple file to file Scenario in XI to a webservice. Regards, Varun.

  • Pblm with If condition... to validate tables

    Hai please see the below code DatabaseMetaData myMT = con.getMetaData(); String[] myTables = {"TABLE"}; ResultSet tables = myMT.getTables(null,null, "%", myTables); String tableName = null; while (tables.next()) tableName = tables.getString("TABLE_NA

  • How to go to specific tab in Safari?

    Say you have 8 tabs opened, you are currently at the first one and you want to navigate directly to tab 6. In Chrome this is achieved by: cmd + 6. How can I configure this to work in Safari 7.0. Thanks.