SQL Server >> Sql query results

by Um1zYW5kcw » Thu, 19 Feb 2004 03:36:11 GMT

I am using sql 2000 and have created the proper table and entries. I am trying to get the following results:

NAME ST
AL FROM IL


Here is the query that does not work, and I would appreciate some help.


select (FIRSTNAME || 'from') NAME, STATE
from FRIENDS
where STATE = 'IL'
and
LASTNAME = 'BUNDY';


Here is the error= Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '|'.



SQL Server >> Sql query results

by Christian Smith » Thu, 19 Feb 2004 03:46:43 GMT


select firstname as 'NAME', (' from ' + state) as 'STATE'
from friends
where state = 'IL'
and lastname = 'BUNDY'

Christian Smith



trying to get the following results:





SQL Server >> SQL Query Results

by Aaron Prohaska » Sat, 11 Sep 2004 01:26:37 GMT

Can anyone tell me why query analyzer sometimes prints "(1 row(s)
affected)" and sometimes prints "The command(s) completed successfully."
even though in both cases I'm doing the same thing, creating a table?

regards,

Aaron


SQL Query Results

by Harman Sahni » Sat, 11 Sep 2004 01:44:19 GMT

Check out the SET NOCOUNT ON/OFF option








SQL Query Results

by Aaron [SQL Server MVP] » Sat, 11 Sep 2004 02:12:01 GMT

Maybe because sometimes you create a table and insert a row, and other times
you just create a table?

--
http://www.aspfaq.com/
(Reverse address to reply.)










Similar Threads

1. Establish relationship beteen SQL query results and Access table - External Data - Access

2. Default value fill with SQL query result

Hi,
I am trying to set the default value of a text box using a SQL query
which depends on the result of a combo box selection made in  a
previous form. But all I get is '#Name?' in the text box.

I have created a SQL query called Q1 which is:
SELECT [client].[name]
FROM client
WHERE clientid=[Forms]![Choose Client]![Combo4];

And then in the 'Default value' for the text box I have put:
=[Q1]

Am I doing this the wrong way? The 'Combo4' is the combo box on the
previous form from which the text box should be set.

thanks for any help.

3. set variable equal to sql query result in VB - Access Forms Programming

4. Passing SQL Query Results into a Variable Using VBA

All,

It has been a long time since I did any access work, so I apologize for the 
simple question:

I am trying to write some code that will do something based on whether or 
not the data exists in the database.  So, I basically want it to proceed 
with the code provided that no rows exist in the access tables that meet 
the criteria.

So I am trying to run a "select count (*) from TABLE Where COLUMN = "XYZ".
I would like to pass this value into a variable so I can create my if then 
statement.

So if = 0 then continue to the next steps.  If > 0, then I would like to 
display the results so the user can clean them up.

Does that makes?  Can anyone help me get this started?

Thanks

5. understanding an sql query result

6. NEWBIE - Join in SQL Query result is omitting records

Greetings,

I have two tables with the following information (simplified):

  a.. InvoiceDetail [PA23203]
    a.. Invoice Line Item Number
    b.. Line Item amount
    c.. Line Item Bill Note Index (joined to [PA01601])
  b.. BillNotes [PA01601]
    a.. Bill Note Index (joined to [PA23203])
    b.. Billing Note


I would like to display a grid with the information in invoice detail and
the billing note in the same grid.  If I do a standard join on the tables,
the query works and all, but it omits all rows that do not have a billing
note.  The result of the query is only showing the invoice detail line items
with an attached note.



I'd appreciate any help you would be willing and able to give.



Below is the SQL statement if you are interested (sorry it's messy and
long):



SELECT [PA23203].[PACostDate], [PA23203].[PACOSTCATID],
[PA23203].[PACostOwner], [PA23203].[PAApproved_Quantity],
[PA23203].[PAUnitCost], [PA23203].[PATotCst], [PA23203].[PAAPPROVMKUPPCT],
[PA23203].[PAApproved_Billing_Amou], [PA01601].[PATX500] FROM [PA23203],
[PA01601] WHERE ([PA23203].[PABillNoteIDX] = [PA01601].[PABillNoteIDX]) AND
[PA23203].[PADocnumber20] = '" &
datagrid2.items.item(datagrid2.selecteditem.itemindex).Cells(0).Text & "'
ORDER BY [PA23203].[PACOSTDATE], [PA23203].[PACOSTOWNER]



Thank you,



-Dave


7. Export SQL query results to text file - Asp.Net

8. Displaying SQL Query Results

I'm completely new to ASP.NET programming, so please accept my apologies in 
advance for asking what is probably an obvious question. :-)



I'm trying to write a page which will display the contents of an SQL record. 
I've added the following code to a file called default.aspx:



<html>

<head>

<title>My sample application </title>

</head>

<body>

<p> Output a database record:</p>



<%@ Page Language="C#" Debug="true" %>

<%@ import namespace="System.Data" %>

<%@ import namespace="System.Data.SqlClient" %>

<script language="c#" runat="server">



public void Page_Load(object sender, EventArgs e) {

            SqlConnection objConn = new SqlConnection("Server=servername; 
Database=database; UId=username; Pwd=password");

            objConn.Open();



            string strQuery = "select * from tablename where field = 
'value'";

            SqlCommand objCmd = new SqlCommand(strQuery, objConn);



            objCmd.CommandType = CommandType.Text;

            SqlDataReader objDR = objCmd.ExecuteReader();





            objDR.Read();

            Response.Write(objDR["field"] + "<br>");





            objConn.Close();



}

</script>



<p>Thus ends my query. </p>

</body>

</html>



The code executes properly and produces the expected results, however its 
printing those results at the top of the page before any of the html. (Even 
though the code is sandwiched between html code)



What am I doing wrong? :-)



Thank You,

Brad