Use value from select query

I am writing to learn if it is possible to obtain a value from a select query, and utilize this value in a succeeding query.

Please see below for my current query.  I would like to take the filenum result, and use the value in a second query.

Thanks in advance! 

select shhd.CUST_NO, shhd.file_no as filenum
tpsdba.shipment_header SHHD
WHERE SHHD.CUST_NO = '052584 '
AND (SHHD.DATE_ENTRY >= '20080401' AND SHHD.DATE_ENTRY <= '20080404') 


4/28/2008 12:39:31 PM 29906 articles. 0 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 21

declare @Result as nvarchar(10)

set @Result = (select shhd.CUST_NO, shhd.file_no as filenum
tpsdba.shipment_header SHHD
WHERE SHHD.CUST_NO = '052584 '
AND (SHHD.DATE_ENTRY >= '20080401' AND SHHD.DATE_ENTRY <= '20080404') )

Click "Mark as answer" when it helps
4/28/2008 1:01:46 PM
Um.  That doesn't look right.
First of all, we need to note that we don't know the correct datatype for @Result, so nvarchar(10) was guessed.  You will need to supply the correct datatype.
Second, the query returns two fields, not one.
Instead of declaring @Result (which is a not a particularly meaningful name), we should declare
@cust_no and @filenum with the correct datatypes.
Third, ASSUMING the sample query returns ONLY ONE RECORD (or we want the last one it retrieves if more than one is found), we move each selected column into its respective variable, like so:
declare @cust_no  varchar(10) -- my guess as to datatype
declare @filenum  varchar(10) -- another guess as to datatype
select @cust_no = shhd.cust_no
      ,@filenum = shhd.file_no
  from tpsdba.shipment_header shhd
 where ... -- fill in the rest.
The next query can reference @cust_no and @filenum.
<sarjoun.najjar> wrote in message

declare @Result as nvarchar(10)

set @Result = (select shhd.CUST_NO, shhd.file_no as filenum
tpsdba.shipment_header SHHD
WHERE SHHD.CUST_NO = '052584 '
AND (SHHD.DATE_ENTRY >= '20080401' AND SHHD.DATE_ENTRY <= '20080404') )

Click "answer" when it helps

4/28/2008 8:37:05 PM

Similar Artilces:

Using selected values from a Multi Select Listbox in a SQL query
I have seen a few post concerning this but don't really understand fully as I am new to this.  I would appreciate any help 1) First I loop through the Listbox control and get the selected values: Dim li As ListItemFor Each li In lbPClass.Items If li.Selected = True Then strPC += li.Value & ", " End If Next Label5.Text = strPC The resulting string looks something like: 101, 102, 100 ,    I get rid of the last space and "," with the following statement Label6.Text = Left(Label5.Text, Trim(Len(Label5.Text) - 2)) 2) I would then like to ...

how to add a query to sql datasource using a value from code behind?
 I have a value in my web form which is received from previous page and i have a sqldatasource in which i have written the query through the wizard.In this query i want to use where clause which tallies the cavlue from code behind :the code in code behind is:value1 = Request("abc")SqlDataSource1.SelectParameters("fid").DefaultValue = value1and in source:  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CoursePortalConnectionString %>"       &nb...

Converting a gridView using an Sql Datasource to a gridview who is not using an SQL DataSource
How can i rewrite this page so that i doesnt make use of an SqlDataSource?  <%@ Control Language="C#" AutoEventWireup="true" CodeFile="LoginHistory.ascx.cs" Inherits="Private_UserControls_WebUserControl" %> <html> <head> <%--<link rel="stylesheet" href="BaldwinPortal.css" mce_href="BaldwinPortal.css" type="text/css" />--%> <title>Login History</title> </head> <body style="margin:0 0 0 0;padding:0 0 0 0"> ...

Srored procedure, sql query not using values in the query
ISSUE: I am attempting to construct a stored procedure that will select select information between two time periods. Well I have tried a couple of queries to find out what would happen to performance. What I have found is the query where the range of dates is entered, hard coded, the Optimizer uses the index. If I use a variable or a calculation I get a table scan and the dates are not used at all in the query. Why is this happening, forcing the index has no effect, see last example. I am using ASE 11.92 on a SUN server, Sun_srv4, sybase build 1031. below are the results of query ...

Use value from one database query to select second query
 Hi, I have the following code, which looks up the value 'comment_id' from a database table (tblPage), then uses that value to look up values from the comments table (tblComment):  protected void Page_Load(object sender, EventArgs e)    {        SqlConnection conn = new SqlConnection("Server=my.server.ip;Database=db;User ID=myusername;Password=mypassword");        conn.Open();                //Page&nbs...

SQL Keyword is used as Field Name. SELECT Query Problem using DBI.
Hello, One of our tables awb_msg has the field name 'text' and when I try to use the DBI to do a select it prompts an error. How can I do this. I can't change the field name as it is in a production environment and has been use for the past 10 years with no problems. We are using ms- sqlserver. And also, I have no control of changing the field name. So, changing the field name is not possible. Here is my test: This is working correctly. -- my $sql = "SELECT seq, create_date, msg_code, send_receive FROM awb_msg where seq = 7989176"; it returns: ...

Problem using two gridviews when using selected value of 1st to control datasource of 2nd
 I have a page with 2 gridviews. When you select a row in the first gridview, the DataKey of that row gets passed to the second gridview, which then displays a list of related records. I've read at that there can be issues around page lifecycle timing that can affect what I'm doing so I've tried to follow the instructions there. However, I'm still having problems.Here's the flow of what I want to happen:a) User clicks row in gridview1.b) Postback occurs.c) gridview1 is selected, gridview2 shows records relating...

Select Query in SQL Datasource
Hi! I am using a oracle, I put this code (below) to a sqldatasource control (Select Query) SELECT A.part_no, (A.beg_invty_qty + A.qty) QTY, X.TT       FROM inventory_master A,     (SELECT C.part_no,TRUNC(((C.beg_invty_qty + C.qty) /      DECODE(SUM(D.NEED),0,1,SUM(D.NEED))),2) TT          FROM inventory_master C, pcs_header D      WHERE C.part_no = D.part_no       and (trunc(D.prodn_date) >= trunc(sysdate) and trunc(D.prodn...

Query to ADD/SELECT values from an SQL
Hello. I need a query that will RETRIEVE a value from a database if it is present, but if the data isn't present, then the data will be INSERTed into the table. Either way, I need the row returned at the end of the query. I can do SELECT queries, but I don't have a clue as to how to proceed with branching statements. For example: User runs a query for "Canada". Canada exists in the database, so the database returns Canada along with its ID. Next user runs a query for "Chile". Chile isn't in the database so a record is created and the ID (an IDENTI...

use value of textbox in SQL query
hello everyone i was using a textbox to allow the user to enter a value and then i wanted to retrieve the value entered in that textbox to use in an SQLquery so that i can retrieve the corresponding data from the database. i tried assigning the value of the textbox to a variable, id, and then using the variable in the query:select 8 from mytable where AppID= '" & id & " ' but this does not work, nor does replacing the varaible by txtbox.TExt work. cAn anybody give me the correct syntax please?Thanks Your Id is Integer right, delete the single quote AppdId = " &...

How to use value calcuated in query in subsequent query, all based on value in querystring?
I have a page that I need to display a list of employees who work in a specific office, based on a MatterID passed in a query string.  But, I don't know how to get a value returned from one sql statement into a second.  Here's what I'm trying to do... From the QueryString, we know that the MatterID = 4  ( xxx.aspx?MatterID=4) Knowing that the Matterid=4, I query the database to get the OfficeId for that MID  (Select OfficeID from tMatter where Mid=4)   ~This returns an OfficeID of 6 So, then I need to do another query to get the employees w...

How to add users to a SQL Server DB used for authentication using SQL query
Hi, I am looking for a simple way to add users manually to a SQL Server DB (set up using aspnet_regsql.exe) via a SQL query. What are the required values, that have to be set in the different tables? Thanks in advance, Markus By default SqlMembershipProvider calls the aspnet_Membership_CreateUser stored procedure to create a user, you can use T-SQL statment like sp_help aspnet_Membership_CreateUser to learn how to use it.Welcome to my SQL/ASPNET forum for Chinese

How Select one dropdownlist value using down arrows corresponding other dropdownlist value are select
I am using two dropdownlist box.One is used for country selection. other one is used for state selection.I am using dropdown selectedindexchanged event. when i click country dropdownlist corresponding state is selected in state dropdownlist box. How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.R.Karthikeyan   kartmca: How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.Generally, we don't implmenet...

Using DropDownList selection in an SQL Query (C#)
I have a DropDownList and a SqlDataSource (see both below) and I want the query in the SqlDataSource to use the DropDownList selection in the query.  I filled it in with something I found online but apparently there is a mistake or it is incomplete so I changed it to question marks.  What am I missing? misusing?  Possibly I need another "using" on the C# code behind page?  Thank you for your help with this.  -Larry  <asp:DropDownList ID="DropDown" DataSourceID="SqlDataSource2" runat="server" AutoPostBack="...

Web resources about - Use value from select query -

Scottish Affairs Select Committee - Wikipedia, the free encyclopedia
The Scottish Affairs Select Committee is a select committee of the House of Commons in the Parliament of the United Kingdom . The remit of the ...

kotaku selects
Kotaku Selects

Facebook Testing Featured Videos in Videos Sections of Select Pages
Facebook confirmed to TechCrunch that it is testing a new design for the videos section of select pages – including ABC News and The New York ...

Hyundai set to bring CarPlay to select cars early next year after delay
... update to be released during the first quarter of 2016 that will enable the CarPlay feature on supported models with a connected iPhone. Select ...

How to Select Sharable Curated Content
Creating and delivering fresh content on a frequent and consistent basis can be a challenge in today’s demanding digital world. Curated content ...

Google Play offering select buy one, gift one movies for the holidays
... a few days ago, Google is giving you the chance to purchase a movie and gift that same movie to a friend for no extra charge. The selection ...

Dezeen selects 10 of David Bowie's most iconic moments
David Bowie was one of the most influential fashion and design icons of the last 40 years. Dezeen picks his best looks, costumes and album covers ...

DEAL: Buy Select Google Play Movies, Gift One to Someone for Free
We’re getting closer and closer to the holidays and gift-giving fever is just around the corner. In the spirit of the season, Google’s latest ...

EA’s Origin Access offers PC gamers unlimited access to select games
For $5 per month you get early access to EA titles on Origin, plus a selection of older games from The Vault at no additional cost.

In Louisiana, High School Football 'Select'-Public Split Gets Put Back Together Again
... school sports teams, traditionally done by size of school, has been for state associations to try to figure out ways to split private or select ...

Resources last updated: 1/17/2016 10:33:54 AM