Response.Write'ing fields with select from mu

Results 1 to 4 of 4

Thread: Response.Write'ing fields with select from mu

  1. #1
    Bas Penris Guest

    Default Response.Write'ing fields with select from mu

    sSQL2="SELECT * FROM link, linktype WHERE linktype.index=" & Request.QueryString("catid")<BR>--end query<BR>Now how do I display the results from a specific table, I&#039;ve tried:<BR>Response.Write rs.Fields("link.naam") but IIS5 responds with an error. Anyone know how to do this?<BR>

  2. #2
    Join Date
    Dec 1969

    Default You have to do it in the SQL...

    You have to specify the fields, one at a time, and give them aliases using "AS". Thus:<BR><BR>SELECT link.field1 AS link_field1, ... , linktype.field1 AS linktype_field1 ...<BR><BR>Naturally, the alias names can be anything you want.<BR><BR>One sneaky trick: Only alias the names in *one* of the tables (the one with fewer fields?) and leave the ones in the other table alone. Thus:<BR><BR>SELECT link.field1 AS L_field1, link.field2 AS L_field2... , linktype.* FROM ...<BR><BR>The other alternative: Don&#039;t use names in your ASP/ADO code. Use positional fields, instead.<BR><BR>Response.Write RS(13) & ": " & RS(5) ...<BR><BR>The problem with that, of course, is that now you have to change the numbers if the table contents change.<BR><BR><BR>

  3. #3
    Leshka Guest

    Default RE: Response.Write'ing fields with select fro

    When you do * select from more than one table there is a chance that tables might have columns with same names.<BR><BR>What you have to do is select all the fields that you want and give each one an alias.<BR><BR>Ex:<BR><BR>Select i.ItemID ItemID, c.CustID CustID FROM Items i, Customers c<BR><BR>Now you can do Response.Write(rs("ItemID")) or Response.Write(rs("CustID"))<BR><BR>This should work.

  4. #4
    Bas Penris Guest

    Default RE: You have to do it in the SQL...

    Thank you very much, I&#039;m just a beginner at SQL, and a good programmer in VisualBasic, but not yet ASP, can&#039;t find any keyword reference on the internet.<BR><BR>Tnx!Tnx!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts