Joining 3 tables with null values
Hi,
I have three tables that have varying data in. I want to write a query which will list all three in the result set, but when one of the tables doesn't have a row, write in No Value.
I will be intending on joining the tables with account numbers. What will be the syntax of a join with three tables where I am not sure which table will have null values?
Thanks...
Something like
select nvl(a.id,'No Value'), nvl(b.id, 'No Value'), nvl(C.id, 'No Value')
from (select id from t1) a,
(select id from t2) b,
(select id from t3) c
where a.id = b.id(+)
and a.id = c.id(+)
Hi,
I have three tables that have varying data in. I want to write a query which will list all three in the result set, but when one of the tables doesn't have a row, write in No Value.
I will be intending on joining the tables with account numbers. What will be the syntax of a join with three tables where I am not sure which table will have null values?
Thanks...
Similar Messages
-
JOIN over 3 tables with 'null' values?
Hello all,
I would like to join data from 3 tables, whereas from the 3rd table I just wanna join 2 columns, if a condition is met. otherwise those 2 columns should be NULL.
The following statement works, but only shows me the rows where all conditions are met. How do I display the rows from JOIN 1 if the JOIN 2 condition is not met?
SELECT
a.c_name, a.c_date, a.c_description, a.c_sid,
b.c_cID, b.type,
c.name, c.value
FROM
TABLE_1 a
INNER JOIN
TABLE_2 b
ON
(b.c_name = a.c_name)
INNER JOIN
TABLE_3 c
ON
(c.c_name = a.c_name)
AND
(c.comp_cID = b.comp_cID)
Thanks a lot and best regards,
TomOUTER JOIN
-
Join table with additional data
Hi,
I'm new to JPA (Toplink Essentials) and I'd like to know how to handle this situation:
I have ORDER table, ITEMS table and "join table" ORDER_ITEMS which holds refernces to ordered items with quantity of each oredered item.
Many thanksI did mapping as shown in listing. It works for reading, but for writing JPA returns error. Can somebody help?
Thanks
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Column name 'idexpedice' appears more than once in the result column list.
Error Code: 264
Call: INSERT INTO vklad_expedice (IDEXPEDICE, IDVKLAD, VAHA, idexpedice, idvklad) VALUES (?, ?, ?, ?, ?)
bind => [null, null, 0, 4411, 2]
@Entity
public class Expedice implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer idexpedice;
@Temporal(TemporalType.DATE)
private Date datum;
@OneToMany(fetch = FetchType.EAGER, mappedBy="expedice", cascade = CascadeType.ALL)
private List<ExpediceVklad> vklady;
@Entity
public class Vklad implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer idvklad;
private String nazev;
@Entity
@Table(name = "vklad_expedice")
@IdClass(ExpediceVkladId.class)
public class ExpediceVklad implements Serializable {
@Id
private Integer idexpedice;
@Id
private Integer idvklad;
private Integer vaha;
@ManyToOne
@JoinColumn(name = "idexpedice")
private Expedice expedice;
@ManyToOne
@JoinColumn(name = "idvklad")
private Vklad vklad;
public class ExpediceVkladId {
@Id
private Integer idexpedice;
@Id
private Integer idvklad;
SQL tables
EXPEDICE
idexpedice
datum
VKLAD
idvklad
nazev
VKLAD_EXPEDICE (this is the join table with additional column)
idexpedice
idvklad
vaha
Edited by: user10933983 on 31.3.2009 13:47 -
JDBC MS Access--- cannot extract entry with null value with data type Meta
I'm trying to extract a data entry with null value by using JDBC. The database is MS Access.
The question is how to extract null entry with data type memo? The following code works when the label has data type Text, but it throws sqlException when the data type is memo.
Any advice will be appreciated! thanks!
Following are the table description and JDBC code:
test table has the following attributes:
Field name Data Type
name Text
label Memo
table contents:
name label
me null
you gates
Code:
String query = "SELECT name, label FROM test where name like 'me' ";
ResultSet rs = stmt.executeQuery(query);
while (rs.next())
String name = rs.getString("name");
rs.getString("val");
String label = rs.getString("label");
System.out.println("\t"+name+"\t"+label);
catch (SQLException ex)
System.out.println(ex.getSQLState());
System.out.println(ex.getErrorCode());
System.out.println("in sqlexception");
output:
C:\Temp\SEFormExtractor>java DBTest
yet SELECT name, label FROM test
null
0
in sqlexceptionThe question is how to extract null entry with data type memo?Okay, what you need to do is this:
if (rs.getString("val") == null)
// do something
}This way, when it's a null value, you can check it first, and then handle it how you want, rather than getting an exception. -
Sql query slowness due to rank and columns with null values:
Sql query slowness due to rank and columns with null values:
I have the following table in database with around 10 millions records:
Declaration:
create table PropertyOwners (
[Key] int not null primary key,
PropertyKey int not null,
BoughtDate DateTime,
OwnerKey int null,
GroupKey int null
go
[Key] is primary key and combination of PropertyKey, BoughtDate, OwnerKey and GroupKey is unique.
With the following index:
CREATE NONCLUSTERED INDEX [IX_PropertyOwners] ON [dbo].[PropertyOwners]
[PropertyKey] ASC,
[BoughtDate] DESC,
[OwnerKey] DESC,
[GroupKey] DESC
go
Description of the case:
For single BoughtDate one property can belong to multiple owners or single group, for single record there can either be OwnerKey or GroupKey but not both so one of them will be null for each record. I am trying to retrieve the data from the table using
following query for the OwnerKey. If there are same property rows for owners and group at the same time than the rows having OwnerKey with be preferred, that is why I am using "OwnerKey desc" in Rank function.
declare @ownerKey int = 40000
select PropertyKey, BoughtDate, OwnerKey, GroupKey
from (
select PropertyKey, BoughtDate, OwnerKey, GroupKey,
RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]
from PropertyOwners
) as result
where result.[Rank]=1 and result.[OwnerKey]=@ownerKey
It is taking 2-3 seconds to get the records which is too slow, similar time it is taking as I try to get the records using the GroupKey. But when I tried to get the records for the PropertyKey with the same query, it is executing in 10 milliseconds.
May be the slowness is due to as OwnerKey/GroupKey in the table can be null and sql server in unable to index it. I have also tried to use the Indexed view to pre ranked them but I can't use it in my query as Rank function is not supported in indexed
view.
Please note this table is updated once a day and using Sql Server 2008 R2. Any help will be greatly appreciated.create table #result (PropertyKey int not null, BoughtDate datetime, OwnerKey int null, GroupKey int null, [Rank] int not null)Create index idx ON #result(OwnerKey ,rnk)
insert into #result(PropertyKey, BoughtDate, OwnerKey, GroupKey, [Rank])
select PropertyKey, BoughtDate, OwnerKey, GroupKey,
RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]
from PropertyOwners
go
declare @ownerKey int = 1
select PropertyKey, BoughtDate, OwnerKey, GroupKey
from #result as result
where result.[Rank]=1
and result.[OwnerKey]=@ownerKey
go
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Range interval partitioning with null value
Hello,
I have question, how can I create table with partition and after that I will insert null value in the partition key like this kind of
range interval partitioning with null value.
I have Oracle 11g.
Thanks
Mohammeduser13777053 wrote:
Thank you, but my question is about range interval not for range?http://docs.oracle.com/cd/E11882_01/server.112/e25523/partition.htm#VLDBG00220
A MAXVALUE literal can be defined for the highest partition. MAXVALUE represents a virtual infinite value that sorts higher than any other possible value for the partitioning key, *including the NULL value.*
So since you're trying to partition by interval (which doesn't support a MAXVALUE clause) you're out of luck.
There's probably fancy hacks and what not you could try to implement, but i'm not about to recommend any of those here :)
Cheers, -
how to transfer database table contain null values, primary key, and foreign key to the another database in same server. using INSERT method. thanks
INSERT targetdb.dbo.tbl (col1, col2, col3, ...)
SELECT col1, col2, col3, ...
FROM sourcedb.dbo.tbl
Or what is your question really about? Since you talke about foreign keys etc, I suspect that you want to transfer the entire table definition, but you cannot do that with an INSERT statement.
Erland Sommarskog, SQL Server MVP, [email protected] -
To overcome column with null value-urgent
hai all,
when i query i get column with null value.
how to solve it?
thank in advance.
rcs
SQL> DESC SCOTT.CB1;
Name Null? Type
ID NUMBER
SUPCODE NUMBER
SUPLNAME VARCHAR2(100)
NAME VARCHAR2(100)
ITEMCODE VARCHAR2(10)
RECDOC NUMBER
RECDATE VARCHAR2(10)
TOTVALUE NUMBER
QTY NUMBER
CB_IPNO NUMBER
CB_VNNO NUMBER
CB_VDT VARCHAR2(10)
CB_AMT NUMBER
RECDOC_GR VARCHAR2(30)
RECDATE_GR DATE
SUPCODE_GR VARCHAR2(10)
TABLE LOOK LIKE THIS (NOT ALL DATA IN SAME ROW, BECUSE I INSERTED LAST 3 COLUMN VALUES):
ID SUPCODE SUPLNAME NAME ITEMCODE RECDOC RECDATE TOTVALUE QTY CB_IPNO CB_VNNO CB_VDT CB_AMT RECDOC_GR RECDATE_GR SUPCODE_GR
2015 AAAA 04117 9083 10545.6 78
2016 BBBB 04609 9087 25200 3600
2017 GGGG 04609 9088 28175 4025
2018 36591371.64 2565017.27
00001/07-08 02/04/2007 14020362
00002/07-08 02/04/2007 14020362
00003/07-08 02/04/2007 14010254
00004/07-08 02/04/2007 14010254
00005/07-08 02/04/2007 14021458
SQL> SELECT DISTINCT ID, SUPCODE_GR, NAME, ITEMCODE, RECDOC, RECDATE_GR, TOTVALUE, QTY FROM SCOTT.CB
1;
ID SUPCODE_GR
NAME
ITEMCODE RECDOC RECDATE_G TOTVALUE QTY
1
PRO.AT.ALU.POWDER UNCOATED
04609 15 51975 7425
2
PEN, GEL PEN
07969 17 154 11
ID SUPCODE_GR
I NEED RESULT AS FOLLOWS (ALL RESPECTIVE DDATA IN ONE LINE NOW NOT LIKE THAT):
ID SUPCODE SUPLNAME NAME ITEMCODE RECDOC RECDATE TOTVALUE QTY CB_IPNO CB_VNNO CB_VDT CB_AMT RECDOC_GR RECDATE_GR SUPCODE_GR
2015 AAAA 04117 9083 10545.6 78 00001/07-08 02/04/2007 14020362
============Even accounting for the formatting, I'm not sure I even understand the question. It could be any number of different problems or non-problems.
-
Pro*C & SQLDA with NULL value for predicate column
Hi: I am using a C program to update a table via a dynamic sql (method 4) and SQLDA. In the update statement predicate, I have place holders (as in TBLCOL=:C000). One of the columns in the predicate contains null values, so I set L[n] = 0, V[n] = pData (which pData[0] = '\0'), *(I[n]) = -1, and T[n] = 5 (for text). I cannot find the row that I know is there.
I cannot change my statement to contain TBLCOL IS NULL, since I don't know ahead of time if I'm looking for rows with null values for this column. The Pro*C manual says that by setting the appropriate *(I[n]) = -1, it indicates to Oracle to simulate the "IS NULL" clause, and update the appropriate rows. In my case, I receive 1403 as SQLCODE when I use TBLCOL=:C000 vs TBLCOL IS NULL. What am I doing wrong? Thank you for your help.You should include these columns as well;
ChangeType (see mxi_changetype)
ValOwner (repository)
UserID ("jobid=<>", usermskey, GUI (mmc), DG (dyngrp), reconcile)
IdAudit (This is the event task (add and del member for assignments)
ParentAuditId (AuditID of parent which last updated the attribute, not consistent)
ChangedBy (Holds the MSKEY of the user which last changed the attribute)
ExpiryTime
to make sure you get a fuller picture of the audit record.
Your selection does not cover all events and descriptions
br,
Chris -
Need help with NULL values in Crosstables
Hello everybody,
I need some help with NULL values and crosstables. My issue is the following:
I have a query (BW - MDX-Query) that gives me turnover measures for each month. In Crystal Reports I choose crosstable to display this whereby I put all month in columns and all turnover-measures in rows. Each month that has a value (measures are not empty) is chown in the crosstables rows. So far so good. The problem occures when there are month that actually have no values (measures are empty). In that case these months are not chown in columns. But I need CR to display these columns and show the value 0. How can I do that?Hi Frank,
Cross tab shows the data based on your column and these column fields are grouped and based on the group it will show your summaries.
If there is no data for any of your group it will not display that group. In this case you will have to create a standard report which should look like cross tab and to get zero values you need to write formulas .
Example if you want to display Moth wise sales :
if Month() = 01 Then
sum() else 0
Now this formula will check if your month is Jan, then it will sum up the values else it will display zero value.
This is possible only through standard report not with Cross Tab.
Thanks,
Sastry -
How to create a dimension object in SAP BW Unv with Null value
Hello,
for query syncronisation task, I need a dimension object in my BW universe with NULL value. Does someone know, how to do it or if its possible?
Regards,
ThiloHi Thilo,
so the only common item is Material then - correct ?
Query 1 Query 2
Formulation (grouping of materials) (No counterpart)
Material Material
dummy key figure (why?) Company Code
10 Keyfigure
Is this something you regular have to do ? what about a MultiProvider ?
did you try "merged dimensions" in the Web Intelligence Report ?
Ingo -
JDBC Receiver Adapter with Null Value
HI,
I have configured ID for JDBC Receiver. In my communication channel, I already check Integration of Empty String Values = Null Value. However, when I check the result from audit log, it still shows that SAP XI sends the null value to database. In my understanding, it should not send the field which has null value (It shouldn't be included in sql statement).
I check this with other scenario. With the same check at Integration of Empty String Values = Null Value, it doesn't send null value to database. It happens only with my first scenario.
Have anyone ever been through this before? Any suggestion please?
Thanks,
PavinHi,
1. The occurrence is 0...1
2. This is the first result with null value (Please see field Error)
UPDATE EXPCRM_T_CustomerProfile SET RequestID=455, RecordNo=1, SAPCustomerCode=0001000344, Error=NULL, Status=2, UpdateDateTime=12/03/2008 13:45:03 WHERE (RequestID=455 AND RecordNo=1)
Then, I change the option from Null Value to Empty string. This is the result.
UPDATE EXPCRM_T_CustomerProfile SET RequestID=455, RecordNo=1, SAPCustomerCode=0001000344, Error=', Status=2, UpdateDateTime=12/03/2008 13:46:12 WHERE (RequestID=455 AND RecordNo=1)
Field Error Change from NULL to '
The expected result from me is that field Error should not exist at all. Please help.
Thanks,
Pavin -
bc4juix:StyledText doesn't work with null values?
Hi , anyone knows why the <bc4juix:StyledText> tag doesn't work with null values?
For example when datasource does not give back data...
Thanks
GuillermoWhich version of Jdev are you using? What are the results you are getting?
-
Update table all null values to 0 single query
hi dear ;
How Can I do , update table all null values to 0 using single query or proceduredeclare @tableName nvarchar(100)
declare @querys varchar(max)
set @querys = ''
set @tableName = 'YOUR TABLE NAME HERE'
select @querys = @querys + 'update ' + @tableName + ' set ' +
QUOTENAME(t.[name]) + '=0 where ' + QUOTENAME(t.[name]) + ' is null;'
from (SELECT [name] FROM syscolumns
WHERE id = (SELECT id
FROM sysobjects
WHERE type = 'U'
AND [NAME] = @tableName))t
select @querys
execute sp_executesql @sqlQuery
Reference:
http://stackoverflow.com/questions/6130133/sql-server-update-all-null-field-as-0
-Vaibhav Chaudhari
this code is return update TABLE set [FIELD]=isnull([FIELD],''),update TABLE set [FIELD2]=isnull([FIELD2],'')
I want to use UPDATE TABLE SET FIELD1=ISNULL(FIELD1,0),FIELD2=ISNULL(FIELD2,0),FIELD3=ISNULL(FIELD3,0) So CUT another update and set statement . -
Populate target table with default value
I have a query like this:
SELECT 0 AS ID,
9999999999 AS CODE
FROM DUAL
UNION ALL
SELECT VEH.TP_ID AS ID,
VEH.VEH_ID AS CODE
FROM TB_VEHICLE;
So I have an interface with two data sets, one for each query.
The first data set represents the "select from dual" "constant values" and the second represents the "select * from tb_vehicle".
In the first data set I don´t have a source, then ODI generates a select without a table "select 0 AS ID, 99999 AS CODE FROM".
Any ideas on how can I achieve my objective? I need to populate one row on target table with constant values.
ThanksAlternatively , try this :
Duplicate the LKM and IKM you are using, create copies , something like LKM xyz (No Source) , IKM xyz (No Source).
Then adust the KM steps accordingly, remove the 'FROM' part and replace with VALUES ( ) , keeping the odiref substitution call in the parenthesis.
So you basically have a knowlede module that accepts no source data, generating :
insert into C$
(col 1, col 2, col 3 etc)
VALUES
(Target mapping 1, target mapping 2, target mapping 3 etc)
I've seen it done, nice and tidy, keeps all the lineage in ODI etc.
Maybe you are looking for
-
How to format a date to display the ISO week number in BI Publisher ?
Hi there, I need to format a date to display the ISO week number in BI Publisher. I've tried the following <?format-date:NEED_BY_DATE;'WW'?>, but it returns a week number (1-53) where week 1 starts on the first day of the year and continues to the se
-
I have two Apple ID's that are causing problems on my new 6+, one of these A ID causes window after window asking for the password. The A ID is linked to the e-mail address that has been deleted and no longer exists. So if I try to use the retrieve P
-
Xslt code to replace a node name to include ns0 prefix
Hi, Is there some easy xslt code to change the following: (I want the ns0 tag and namespace introduced in the root node so that my mapping works. I have created the mapping using externally provided wsdl, but the input message expects the prefix ns0
-
Installer doesn't work after upgrading to 10.3.3
Hi, I'm trying to upgrade from 10.2.8 to 10.3.9. I bought the upgrade to 10.3.3 and installed it (with the upgrade feature, not the archive and install) and now when I try to open the .pkg file for the upgrade to 10.3.9, the installer doesn't work. I
-
TS3989 Can you use the search function in a shared photo stream? How?
Can you use the search function in a shared photo stream? When I try to search in the shared photo stream it goes to search in my photos.