SELECT statement Questions


Accessing another database using a variable
I have a select like this: SELECT a.part_id, a.descript, b.location from PART_MASTER a, anotherdatabase.INVENTORY b where a.part_id = b.part_id Is it possible to use a @variable to identify the other database, rather than hard coding it? (I’ve tried @db2.INVENTORY b) but SQL SERVER 2000 doesn’t like that.

Answer Question   |  October 10, 2008  4:22 PM
SELECT statement, SQL Server 2000, SQL Server database, Variables
asked by:
120 pts.

SQL Server equivalent of Oracle’s “when no data found” exception
In a stored procedure, I’m storing the result of a select statement in @variable. Is there a way to capture a SQL Code 100, like Oracle’s SQLERRM(100)/ORA-01403 if no records are returned? I’m currently setting @variable = ‘*’ before the select and and IF @variable = ‘*’ afterwards, but there must be a more elegant [...]

Answer Question   |  March 6, 2012  2:41 PM
SELECT statement, Stored Procedure variables, Stored Procedures
asked by:
120 pts.

SQL Subfile and position to ability
I have a subfile that can be sorted by any of 4 fields, so I want to use imbedded SQL to read the data out of my PF in order to populate the subfile. I want to be able to allow the user to enter position to information, and position to that entry – normally, [...]

Answer Question   |  August 15, 2008  7:03 PM
SELECT statement, SETLL, SQL Subfile, Subfile
asked by:
Klw
50 pts.

join tables with nested select count and group by
hi i am having three tables : state, agencydetail, parentdetaills i am running following queries but i am getting wrong result plz help me out where is the problem select state.state,count(ag.agencycode) as registag,count(ff.agencycode) as reportag,count(inp.regno) as incpwait,count(interp.regno) as intercpwait from state left outer join (select distinct agencycode,state from agencydetail) ag on state.state=ag.state left outer join [...]

Answer Question   |  July 29, 2008  6:28 AM
Database programming, JOIN statement, SELECT statement
asked by:
5 pts.

CASE sintaxis error in SELECT
In the middle of a large storage procedure I have a working SELECT 01 (see below) which at a couple of points uses CASE statement. I need to expand the most inner CASE to get SQL Server check for several values instead of one. Currently CASE I am talking about looks like (it is in [...]

Answer Question   |  July 19, 2008  7:46 PM
CASE statement, SELECT statement, SQL Server 2005, T-SQL
asked by:
5 pts.

SQL: Using a column created in the SELECT in the WHERE CLAUSE
Can I use a column in the WHERE clause that I created with ‘AS’ in the WHERE clause. I have tried and SQL tells me that the column is not in the table? Thanks, Ray

Answer Question   |  July 9, 2008  7:26 PM
SELECT statement, SQL, SQL statements
asked by:
30 pts.

Calling a stored procedure in a SELECT list on SQL Server 2000
I am using SQL Server 2000, and my question is: is there any way to call a stored procedure in a SELECT list?

Answer Question   |  October 9, 2008  8:16 PM
SELECT statement, SQL Server 2000, SQL stored procedures, Stored Procedures
2,585 pts.

Optimizing Query
Hi, I am having a table which is having around 170 Columns(Don’t blame me but my Developer) and there are only 989 records in the table.I created all sorts of Indexes but still the query (Select * from Table) takes almost 2 mins to display 989 records.I need all the columns to be displayed.Is there [...]

Answer Question   |  July 4, 2008  11:30 AM
Database performance and tuning, Query optimization, SELECT statement
asked by:
15 pts.

Need help executing MULTIPLE SQL extracts from a JCL
GREYBEARD52: Thanks again for the info, BUT I’m not sure if a CL command can be used with a JCL. Can it? ALSO, my JCL uses the SELECT command, so it appears that the RUNSQLSTM command won’t help – it doesn’t support SELECT. Are there ANY OTHER ALTERNATIVES or a way to tweek this command [...]

Answer Question   |  January 27, 2010  6:57 PM
DB2, JCL, SELECT statement, SQL
asked by:
105 pts.

update a field from a file with a field from a selection from two files
Hi! When I try this: update fileD d set d.value = (select c.value from (select b.key, b.value from fileB b where b.key not in (select a.key from fileA a)) c where d.key = c.key) I get the message “Null values not allowed in column or variable VALUE.” on the other hand, when I do this [...]

Answer Question   |  April 29, 2008  11:03 AM
SELECT statement, SQL, Update
asked by:
Mr.
70 pts.

Using SELECT statements
Can we get the number of saturdays in any month using a SELECT statement(i.e without creating a table or function)? If so, can you give me the logic?

Answer Question   |  February 28, 2008  9:48 PM
Oracle, Oracle development, SELECT statement
asked by:
190 pts.

Showing all records
DATA SET: Table1 XID YID WRKDATE — — ——- 1 NOR 2007-01 2 SOU 2007-03 Table2 XID ZID QTY — — — 1 PEN 10 1 PAP 20 2 PAP 5 1 PEN 10 2 PAP 5 Result XID YID WRKDATE ZID QTY — — ——- — — 1 NOR 2007-01 PAP 20 1 NOR [...]

Answer Question   |  November 27, 2007  2:58 AM
JOIN statement, SELECT statement
asked by:
15 pts.

oracle quires
while executing the following qurie ‘inser into custmaster select * from tnjcust where seccode=’431′;’ answer is not enough valus

Answer Question   |  October 29, 2007  1:36 PM
Oracle, SELECT statement
asked by:
0 pts.

Nested Selects in CLLE
I am attempting to palce Nested Select Statements within a CLLE program and it will not accept the process. ie: SELECT wHEN a=B THEN(DO) PROCESS…. ENDDO WHEN C=D THEN(DO) PROCESS eNDDO WHEN (X=Y) tHEN(DO) select wHEN X1 = A tHEN(dO) PROCESS eNDDO wHEN X1 = b THEN(DO) PROCESS eNDDO eNDselect wHEN X=z tHEN(DO) ENDDO ENDSELECT [...]

Answer Question   |  October 24, 2007  7:11 PM
CLLE, NESTED, SELECT statement
asked by:
20 pts.

Select from table where data row missing
I have a table with the main fields being BU, ASSET, BOOK for any BU and ASSET combination, there should be two to four rows of data, with just the BOOK value being different. Data corruption has caused us to find all BU-ASSET combinations missing the value ‘AMT’ for BOOK. I need to join the [...]

Answer Question   |  October 25, 2007  9:34 PM
OUTER JOIN statement, SELECT statement
asked by:
0 pts.