How Pass Column To Udf In Join

Jul 23, 2005

Group,

Passing inline values to a udf is straightforward. However, how or is it
possible to pass a column from the select of one table into a udf that
returns a table variable in a join to the original table. The goal is to
explode the number of rows in the result set out based on the result of the
udf. Although the example I am providing here is simplified, we are trying
to parse out multiple values out of a text column and using a select into so
the result will be one row for each of row in the original table compounded
by the number of occurrences in the text field.
(I know bad table design but that's out of my control)

Thanks,
Ray

create table TableOne
(
Col1 int,
Col2 char(5)
)
go

insert TableOne values (1, 'One')
insert TableOne values (2, 'Two')
insert TableOne values (3, 'Three')
go

Create Function dbo.udfTableTwo
(@Id int)
RETURNS @tbl TABLE (TID int, TChar char(1))
AS
BEGIN
Declare @test int
set @test = @Id
While @test >= 0
Begin
INSERT @tbl VALUES (@Id, Char(65+@test))
set @test = @test - 1
End
RETURN
END

--works
select a.*, b.* from TableOne a join dbo.udfTableTwo(2) b
on a.col1=b.TID

--Fails with Line 1: Incorrect syntax near '.'.
select a.*, b.* from TableOne a join dbo.udfTableTwo(a.col1) b
on a.col1=b.TID

drop table TableOne
go
drop function dbo.udfTableTwo
go

View 6 Replies


ADVERTISEMENT

Integration Services :: Pass Single Column Of Values From Successful Merge Join To EXECUTE Statement

May 7, 2015

How do I pass a single column of values from a successful merge join to an EXECUTE SQL statement so it can be used with an "IN" criteria of the WHERE clause?  Here's an example of my update statement with two random key values:

UPDATE dbo.MyTable SET MyStatus = 1 WHERE MyPK IN ("XYZ123", "DEF890")

Is this even possible in SSIS, or am I better off using a loop and running the update EXECUTE SQL Statement for each individual key value, as in the following example?

UPDATE dbo.MyTable SET MyStatus = 1 WHERE MyPK = "XYZ123"
UPDATE dbo.MyTable SET MyStatus = 1 WHERE MyPK = "DEF890"

View 6 Replies View Related

Join To A List Of Values During Pass-through

Feb 3, 2015

We're using MS Access 2010 as a frontend to an SQL server back-end. From Access, I can run read-only queries and pass-through queries. I'd like to use a local Access table as part of a join to server data. As a non-pass-through query, it's slow; about 5 min to join to 2 other tables.

I could use VBA to turn the local table into part of a pass-through query, with a large in() statement, or several where x='' ors but the local table may have 50000 entries in it. Is there a good or right way to pass this data in the query if I don't have write access to the server?

View 2 Replies View Related

How To Md5 Pass Column By Command ?

Jul 20, 2007

Hi all, i have a database, the password column is normal format , and i want to update all the data in the column password to md5 format , can any one tell me what the command for me to do it ?

is this command will work ?

update tbl_MEMBERS set clm_password=(md5(clm_pass) where id<100

any one have ideas how to do it?

bbboy

View 1 Replies View Related

How To Pass Column Name Trough A Parameter

Jul 12, 2004

Hello ,please help me
Is it possible to pass a column name through a parameter
something like this
create procedure dbo.paramerers
@parameter varchar
as
select @parameter from table1 where....

because it doesn't give me an error but it also doesn't work

View 1 Replies View Related

Pass Column Name Using Parameter In SQL Statement...

Oct 19, 2007

Hi,I am trying to Pass Column Name(FieldName) using Parameter in SQLStatement... But i am getting error...how can i pass Column name using parameter???Example:in table i have fieldname ECountry...Select @FName='ECountry'Select @FName from Table...How it works???Thanx in Advance,Regards,Raghu...

View 5 Replies View Related

Transact SQL :: SUM Of Two Table Column Base On Another Column Value And SUBTRACT And Join Tables

Oct 14, 2015

I have the following table

Table Name EmployeeInformation
EmployeeID EmployeeFirstName EmployeeLastName
    1             |John                       |Baker
    2             |Carl                        |Lennon
    3             |Marion                    |Herbert

Table Name PeriodInformation
PeriodID PeriodStart PeriodEnd
    1        |1/1/14      |12/30/14
    2        |1/1/15      |12/30/15

[code]...

I want a query to join all this tables based on EmployeeID, PeriodID and LeaveTypeID sum of LeaveEntitlement.LeaveEntitlementDaysNumber based on LeaveTypeID AS EntitleAnnaul and AS EntitleSick and sum AssignedLeave.AssignedLeaveDaysNumber based on LeaveTypeID  AS AssignedAnnaul and AS AssignedSick and subtract EntitleAnnaul from AssignedAnnual based on LeaveTypeID  AS AnnualBalance and subtract EntitleSick from AssignedSick based on LeaveTypeID  AS SickBalance

and the table should be shown as below after executing the query

EmployeeID, EmployeeFirstName, EmployeeLastName, PeriodID, PeriodStart, PeriodEnd, EntitleAnnual, AssignedAnnual, AnnualBalance, EntitleSick, AssignedSick, SickBalance

View 4 Replies View Related

Pass NVARCHAR (or Other String-type) Var As A Column Or Table Name In SQL

Jun 21, 2004

Hey folks, the question is fairly simple, unfortunately the answer has proven rather elusive.

Is it possible to declare a variable which would then be used to identify either a column or table in an SQL statement?

Here's a basic idea of what I'd like to do:

DECLARE @myVar AS NVARCHAR(50)

SELECT *
FROM @myVar

or

DECLARE @myVar AS NVARCHAR(50)

SELECT @myVar
FROM MyTable



I'm probably looking for some sort of built in function that will accept an argument here... like COLUMN(@myVar) or something of the like. I just don't know where to look...

View 1 Replies View Related

T-SQL (SS2K8) :: Pass A Column Name Using Parameter In Select Statement

Sep 5, 2014

I have a temp table that hosts data from a MDX query, I want to select a column from that table by passing in a parameter and then insert to a new table.

Here's the table structure, let's call it #temp

[Product].[Product Hierarchy].[level 03].[Member_CAPTION], [Measures].[Gross Sales]
Bike, 200
Accessory , 100

I have a table in the DB created as [ProductSales]

Here's what works for me:

insert into [ProductSales](Product, Sales)
Select convert(varchar(20), "[Product].[Product Hierarchy].[level 03].[Member_CAPTION]") as 'Product' , convert(decimal(18,2), [Measures].[Data]) as 'Sales'
From #temp

But in reality the product level is not always on level 03, I want to define a parameter @Product and pass it to the select list.

Here's what I tried to do:

Declare @Product varchar(500) = convert(varchar(20), "[Product].[Product Hierarchy].[level 01].[Member_CAPTION]")
Declare @SQL varchar(MAX)
SET @SQL='insert into [ProductSales](Product, Sales)
Select '+@Product+' as 'Product' , convert(decimal(18,2), [Measures].[Data]) as 'Sales'
From #temp'
Exec @SQL

But it threw me error, what is the right way to do it, is it because the double quote or single quote thing?

View 1 Replies View Related

How To Pass Pass The Parameter In SQL Command In SSIS Package

Jul 31, 2006

Hi

   We already used Oracle Datasatage Server the following Query statement for Source and Lookup.here there is parameter maping in the SQl Statement . How can achive in SSIS the Folowing Querystatment?

 

Query 1: (source View Query)
SELECT
V_RDP_GOLD_PRICE.GDR_PRODUCT_ID, V_RDP_GOLD_PRICE.ASSET_TYPE, V_RDP_GOLD_PRICE.PREFERENCE_SEQ, V_RDP_GOLD_PRICE.RDP_PRICE_SOURCE, TO_CHAR(V_RDP_GOLD_PRICE.PRICE_DATE_TIME,'YYYY-MM-DD HH24:MI:SS'), TO_CHAR(V_RDP_GOLD_PRICE.REPORT_DATE,'YYYY-MM-DD HH24:MI:SS'), V_RDP_GOLD_PRICE.SOURCE_SYSTEM_ID
FROM
V_RDP_GOLD_PRICE V_RDP_GOLD_PRICE
WHERE
REPORT_DATE = (select max(report_date) from V_RDP_GOLD_PRICE where source_system_id = 'RM' )



 

Query 2: (look up )

 


SELECT
GDR_PRODUCT_ID,
TO_CHAR(MAX(PRICE_DATE_TIME),'YYYY-MM-DD HH24:MI:SS') ,
TO_CHAR(REPORT_DATE,'YYYY-MM-DD HH24:MI:SS')
FROM
V_RDP_GOLD_PRICE
where
GDR_PRODUCT_ID = :1 and
report_date = TO_DATE(:2,'YYYY-MM-DD HH24:MI:SS')  AND
PRICE_DATE_TIME BETWEEN TO_DATE(:2,'YYYY-MM-DD HH24:MI:SS') - 7) AND TO_DATE(:2,'YYYY-MM-DD HH24:MI:SS')
GROUP BY GDR_PRODUCT_ID, TO_CHAR(REPORT_DATE,'YYYY-MM-DD HH24:MI:SS')



 

please anyone give the sample control flow  and how to pass the parameter?

 

Thanks & regards

Jeyakumar.M

 

View 1 Replies View Related

Join On One Column

Sep 8, 2014

I have two tables.

One called Boats with fields

IDSerialNo AreaCompany

There is another table called Equipment with fields

ID is the same in Boats as the ID in Equipment (Foreign Key).There can be multiple Parts linked to ID.I want to be able to return all the rows from Boats but only the Parts for each ID from Equipment. I dont want the other fields appearing more than once in the query.

View 4 Replies View Related

SQL Query To Join A Column On A Row

Apr 3, 2007

I have 2 tables, my vehicle data table and my config table. I need a
query to join them by a datarow and a data column. Heres my tables...config table--------------------id   name   type--------------------1    make   varchar2    model  varchar3    color  varcharveh table--------------------------id   make   model   color--------------------------1    chevy  s10     white2    ford   ranger  silver2    chevy  blazer  brownrecordset needed for veh.id=1---------------------------id   name   type     value---------------------------1    make   varchar  chevy2    model  varchar  s103    color  varchar  white  Thanks for any helpRyan 

View 1 Replies View Related

Multiple Column Join

Aug 16, 1999

I have two tables, one of which is a key table with a subaccount number and a set of attributes that define that subaccount. I am trying to join this key table with the table with all the attributes and come up with one table of subaccounts. The Subaccounts should only lookup the attributes associated with them, not all of the attributes, so I put OR [attribute] IS NULL in the WHERE clause so it only matched on the appropriate columns. This worked great in an initial test with two attributes but when I put all 9 attributes in it crashed with this message "Msg 415, Level 16, State 1
The current query would require an index on a work table to be built with 15 keys. The maximum allowable number of keys is 16"
like this
CREATE VIEW subaccounts
(Subacct_no, balance)
AS SELECT
(s.Account_No + "." + r.Subacct_Ext, S.Balance)
FROM Acct_Rcd r, Subacct_Key s
WHERE
(s.attr1 = r.attr1 OR s.attr1 IS NULL)
AND (s.attr2 = r.attr2 OR s.attr2 IS NULL)

View 3 Replies View Related

ORDER BY - Join Column

Apr 6, 2007

Hi, I am writing a small search engine.
There are two tables. The first one holds the search engine main index, the second one is link table.
I have the following query that retrieves results. I would like to sort the results by:
dbo.OCCURS2(LOWER(:query),se_links.anchor). se_links.anchor obviously comes from se_links table, so I get an error. Is it possible to done in one query?
I'm using MSSQL 2005. Thanks.
PS. Function OCCURS2 returns number of occurrences of one string in other.

Code:

select
id as Id,
uri as ElementUri,
size as Size,
modified_date as ModifiedDate,
title as Title,
text as Text,
dbo.OCCURS2(LOWER(:query),Title) as TitleOcc,
dbo.OCCURS2(LOWER(:query),Text) as BodyOcc
FROM se_index
WHERE (title LIKE :query) OR
(text LIKE :query) OR
(id IN
(SELECT se_links.target_index_id
FROM se_links INNER JOIN
se_index AS se_index_1 ON
se_links.target_index_id = se_index_1.id AND
se_links.anchor LIKE :query))

View 1 Replies View Related

How To Join In As A Partial Column

Oct 2, 2013

We have here 3 tables which are linked by Order number. there is one more table we need to use to get the Shipping zone code. This column however is 10 pos. ( the order number on that table)whilst the others are all 8. We want to join on MHORDR in the table MFH1MHL0, then we are done.

SELECT
ALL T01.OHORDD, T03.IHINV#, T01.OHORDT, T01.OHJOB3, T01.OHORD#,
T02.IDPRLC, T02.IDNTU$*(IDSHP#) AS EXTSHP, T02.IDPRT#
FROM ASTDTA.OEORHDOH T01 LEFT OUTER JOIN
ASTDTA.OEIND1 T02
ON T01.OHORD# = T02.IDORD# LEFT OUTER JOIN
ASTDTA.OEINHDIH T03
ON T01.OHORD# = T03.IHORD#
WHERE T01.OHOSTC = 'CL'
AND T01.OHORDD >= 20120101
ORDER BY T01.OHORD# ASC

View 5 Replies View Related

Join With Parsing From Another Column

Nov 26, 2013

How to accomplish a join when the join condition has to be parsed from another column? I need a list of all the exchange part numbers with exchange part pricing, but need the description from the original part number. Example:

Part Number Description Cost
123-456-1 A ROUND THINGIE 5
150-387-1 EXCH - 123-456-1 2

Needed record is
Part number ExchangePart Description Cost
123-456-1 150-387-1 A ROUND THINGIE 2

Something like

SELECT PART# as exchangepart,
case
when substring(descr, 1,4) = 'EXC-' then trim(substring(DESCR, 5, 25))
when substring(descr, 1,3) = 'EXC-' then trim(substring(DESCR, 4, 26))
when substring(descr, 1,6) = 'EXC - ' then trim(substring(DESCR, 7, 23))
when substring(descr, 1,5) = 'EXCH-' then trim(substring(DESCR,6,24))

[Code] .....

View 2 Replies View Related

Outer Join Column

Mar 17, 2006

Thanks in advance for any help.I'm trying to attempt the following with one table/query.I have a table called TABLE_1It has the following fields:SSNTITLELOCATION322EXDALLAS568REPFT_WORTH536EXDALLAS485SLSYOUNGSTOWN854BROFEEDER258EXEVANSVILLE478TEMPTROY861SLSDALLASI want toselect SSN, TITLE, LOCATIONfrom table_1where ssn = ('322', '536', '258', '478', '861')and title = 'EX'and location = 'DALLAS'The problem, however, it that I want all of the SSN records on my list.My table should look like this:SSNTITLELOCATION322EXDALLAS536EXDALLAS258nullnull478nullnull861nullnullI can easily do this on two tables with a left outer join. I do notknow how to accomplish same (theory) with one table.Any help on how to do this would be appreciated. Thanks

View 8 Replies View Related

To Return Distinct Column Using INNER JOIN

Apr 23, 2008

Hello all,

I am using INNER JOIN to connect 2 tables together but I wish it to return distinct columns instead of repeating itself !

eg.
Current output would be:
UserID Name UserID OrderID
1 John 1 5
2 Bob 2 6

I want it to be:
UserID Name OrderID
1 John 5
2 Bob 6


I need to use SELECT * as there are many many columns and wish to save time :)


Cheers,

James

View 3 Replies View Related

Join Two Columns Together To Form A New Column

Feb 1, 2014

I'm trying to join two columns together to form a new column

My code is basically in the form of can't post the actual since it would be cheating--school assignment

SELECT Column1Name,Column2Name, Column3Name,Column4Name,
Column1Name+Column2Name AS NewColumn1
Column3Name+Column4Name AS NewColumn1
FROM OriginalTable

View 1 Replies View Related

Inner Join Based On Conditional Column

Mar 5, 2014

I Have Table Called 'Sales' and 'Voucher',I Need To Show Each Customer ""Dueamount"" Details Based Upon Customer Paid in 'Voucher' Table But One thing I have Not Maintained Transaction History For Customer in 'Sales' Table Means I Have Column named "CreditAmount" in 'Sales' and Column Named "VoucherAmount" in 'Voucher' ,For every transaction I am updating Column named "CreditAmount" in 'Sales', So finally 'Dueamount' Must be calculated according to "VoucherAmount" of customer in 'Voucher' Table....

Sales Table:

BillMasterId BillDate CustomerId NetAmount CreditAmount

26 03/03/2014 101 1000 1000

My Query:
SELECT CONVERT(varchar,BillDate,103) as BillDate,isnull(NetAmount,0) as BillAmount, case when VoucherAmount != 0 then sum(VoucherAmount)else 0 end as'AmountReceived',case when CreditAmount !=0 then CreditAmount else 0 end as 'DueAmount' from Voucher INNER join Sales on CustomerId=CustomerID and BillMasterID=BillMasterID WHERE CONVERT(varchar,BillDate,103)='03/03/2014' AND CustomerId=101

My Output:

BillDate BillAmount AmountReceived DueAmount

03/03/2014 1000 0 0
03/03/2014 1000 500 0
03/03/2014 1000 300 0
03/03/2014 1000 200 0

Exact Output:

BillDate BillAmount AmountReceived DueAmount

03/03/2014 1000 0 1000
03/03/2014 1000 500 500
03/03/2014 1000 300 200
03/03/2014 1000 200 0

View 7 Replies View Related

Newb - Mutiple-column Join

Mar 23, 2007

Hi,very new to SQL queries, and strugling with join conceptI had to do a join based on a single field:select*fromtableA, tableBwheretableA.value = tableB.value(+);this works finebut how can i do the same thing while comparing multiple columns ... iwas thinking something like this: (obviously doesn't work)select*fromtableA, tableBwhere[tableA.value1, tableA.value2] = [tableB.value1,tableB.value2](+);Is there some sort of "tuple" comparison I can do?Thank you.

View 2 Replies View Related

Join To Select A 'weighted' Column

Mar 28, 2006

Perhaps is just brain drain but i cannot seem find an efficient query to join two tables (inv and supplier) such that an inv item can have multiple suppliers and i would like to choose the prefered supplier based on the current 'weight' column.

declare @inv table (item varchar(50), supplierid int)

declare @supplier table (supplierid int, weight int)

set nocount on

insert into @inv values ('item1', 1)

insert into @inv values ('item1', 2)

insert into @inv values ('item2', 2)

insert into @inv values ('item2', 3)

insert into @supplier values(1, 30)

insert into @supplier values(2, 20)

insert into @supplier values(3, 10)

-- the query should return the item and the supplierid associated to the lowest weight
-- item1 -> supplier 2
-- item2 -> supplier 3

select item, ps2.supplierid from @supplier ps2 join

(select item, min(ps.weight)'weight'

from @inv inv join @supplier ps on inv.supplierid=ps.supplierid

group by item) iw on ps2.weight=iw.weight

Is there a better alternative to this?

Thanks in advance,

Mike

View 3 Replies View Related

Dynamic Join Based On Column Value??

May 4, 2007

Hi,

I have three tables.

The "Master table has a recordid, a masterID, a "IsSubField" and other stuff.



I need to do a join to a second table based on the MasterID...



However for each record, if the "IsSubField" has a True value then it has to use table A to JOIN to, where as if it's False, then it uses table B.



Make sense?



Anyone got any pointers?



Thanks in advance

James

View 8 Replies View Related

Join Two Datasets From A Similar Column

Apr 23, 2008

Hi, I was wondering wich is teh easiest way to solve this:


I have one data set that comes from a sql query with many columns.

I have another data set that comes from a txt file that I am reading.

Both data set have one column in common (for example ID).

In the sql data set, I have many rows and I want to keep only the ones that have the same ID from the data set of my txt file. It looks like a inner join if we talk in sql terms.

So, which is the easiest way to solve this?
Thanks!

View 6 Replies View Related

SP With Inner Join - Update Table Value (Single Column)

Oct 16, 2015

I'm trying to do the following:

update a tables value(a single column), based on a query of another database, using a common column.

Here's what I've cooked up so far:

Declare @trackingNo nvarchar (50)
Set @trackingNo =
(
select tracking_no from P21_Shipping.dbo.shipping_data t1
inner join P21.dbo.oe_hdr t2 on t1.order_no = t2.order_no

[Code] ...

print @trackingNoThe error it's returning is:

Msg 512, Level 16, State 1, Line 3
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

So, I'm wanting to query Shipping_data for order_No that matches the same orderNo column value in P21 Database(oe_hdr table), then update P21 oe_hdr table with "trackingNo from Shipping_data

View 8 Replies View Related

Move Column Of Data To Another Table With A Join

Oct 12, 2013

I have two tables. They both have an identity field to join them together. One of the tables has a column of data that I want to put in the other table. I need to make sure the data is brought over using the join so it updates that column for the right record.

I am struggling with this. Should I use a update or an insert? I'm leaning toward update but I can't figure out how with the join.

This is what I have tried so far:

Update grpcon.GroupID = groups.GroupID
from grpcon Inner Join groups
on grpcon.GroupNum=groups.GroupNum

View 1 Replies View Related

Join Tables With Almost Identical Column Data

Oct 29, 2014

Selecting the data from these two tables? The columns 'host_ext_id' have the same data BUT in 'adrmst' all data is preceeded by A0000.

table is 'adrmst'

Host External IDAddress NameAddress Line 1Address Line 2City StatePostal Code
A000042401 T-3803VC 1530401 00 WENGER STTOPEKA KS66609
A000042402 CO INC 960 PP TOMLIN MILL RDSTATESVILLENC286258332
A000042403 CO INC 1420 PP BLVD GARYSBURGNC278319748
A000042405 CO INC 1419 PP BROWN RD KISSIMMEEFL347463415
A000042405 CO INC 962 PP COMMERCE DRVALDOSTAGA316011206

table is 'shipment'

Shipment IDHost External IDcar_move_idP_DEST_LOC_ID
42401 42401
42402 42402 SDQD_00862TAGSDQD
42403 42403 SDQD_00863TAGSDQD
42404 42404 SDQD_00863TAGSDQD
42405 42405 SDQD_00863TAGSDQD

View 4 Replies View Related

Dynamic Column Sorting After Merge Join

Feb 25, 2008



Hello,
I have data coming in from two sources, one being SQL and the other being Oracle. The end result needs to be a CSV file with the columns in a specific order. I have a Data Flow task setup that takes both sources and does a Merge Join on them. I can add a Sort Transformation and manually set the sorting of all 156 columns that end up going to a CSV file destination. However, I have a table setup that holds the names of the 156 columns and the order that the CSV file expects them to be in. I would much rather do this step dynamically as the column names and order may change in the future. Anyone who has used the Sort Transformation for a large number of columns knows how tedious it can be and how adding a column in the middle will cause you to change the sort # for each of the columns that come after it.

So I added a Script Component between the Merge Join and the Flat File Destination hoping that I could alter the order of the columns there. However I added the following code and found that the SortKeyPosition is ReadOnly.


Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)


Dim column As IDTSInputColumn90

For Each column In Me.ComponentMetaData.InputCollection(0).InputColumnCollection



column.SortKeyPosition = 1

Next

End Sub

I was hoping to add some code to get the sort index from my table for each of the columns and set it to the SortKeyPosition. Has anyone out there done this before or seen an example that might point me in the right direction? I've searched for 2 days without coming up with much.

Thanks!


View 5 Replies View Related

Lookup Transformation Join Column Types

Sep 1, 2006

Does anyone have a clue as to why DT_R4, DT_R8 are not allowed as join columns? This means I cannot join tables on AccountNumbers, InvoiceNumbers, etc. What a pain...

View 3 Replies View Related

Join-Problem (select Two Columns Out Of One Column)

Oct 27, 2007

Hi I'd like to select two columns out of one column from another table. Example from source table:





Code Block

ID ArtNr EAN
1 4711 51323135
1 4712 84651213
1 4713 84351322
2 4711 86431313
2 4714 23546853
1 4714 54646545
2 4715 64684353
2 4716 65435132


I want to join this table to a base table with one select, and generate the following output. The ID identifies If the ArtNr has an EAN1 or EAN2:







Code Block

ArtNr EAN1 EAN2
4711 51323135 86431313
4712 84651213
4713 84351322
4714 54646545 23546853
4715 64684353
4716 65435132

View 20 Replies View Related

Transact SQL :: Create Join On Aliased Column

Jun 20, 2015

This is my syntax, but it keeps presenting an error of 'Invalid Column name Last Resort

Select fb.foo, fb.man, cz.choo, 'Hi' As [Last Result]
From foobar As fb
Inner Join chezter As cz
On fb.username = cz.username
and [fb].[Last Result] = [cz].[Last Result]

View 3 Replies View Related

Transact SQL :: Modifying A JOIN When New Column Is Introduced

Jun 25, 2015

At present I have a logic implemented like below code example where I can get a combination of columns cid and ani in 'config' table to which I have to map columns cid and ani present in my 'current' table.

Now, a new column pid is added to both 'config' and 'current' tables, like

alter table config add pid integer 
alter table current add pid integer

Now I can have data in a combination of cid and ani (where pid can be NULL) or cid and pid (where ani can be NULL) or a row where all cid, ani and pid can have values. In this scenario, how should I make the changes in the current implementation given below?

create table current (cid integer, ani integer, resetdate datetime, threshold integer)
create table config (cid integer, ani integer, resetdate datetime, threshold integer )
SELECT cid, ani from
(
SELECT A.cid,
A.ani,
CASE WHEN C.cid is null then B.resetdate ELSE C.resetdate END AS resetdate,

[Code] ....

View 2 Replies View Related

Can Any One Tell Me The Difference Between Cross Join, Inner Join And Outer Join In Laymans Language

Apr 30, 2008

Hello

Can any one tell me the difference between Cross Join, inner join and outer join in laymans language

by just taking examples of two tables such as Customers and Customer Addresses


Thank You

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved