How Can I Split Fields And Depending One Column Decide The Foreing Key

Oct 19, 2007

I´m wondering how to solve the following scenario with SSIS

I have a CITY table and a STATE table, I have to load a file with the information regarding to the CITY:


the state table is like this:


StateCode(PK) stateLegalCode stateName
============= ============== =========
1 01 Florida


the city table is like this:


citycode(PK) cityLegalCode cityname StateCode(FK)
============ ============= ======== =============
1 1001 Quakertown 1


the file has the following information


cityLegalCode cityName
============= ========
01-1001 Quakertown
...

how can I load the file into CITY table:

1-) with the file's cityLegalCode I have to split the string and if the two initial digits are 01 the registry must have 1 in the StateCode(FK).

how can I do something like that using SSIS???

thanks

View 3 Replies


ADVERTISEMENT

T-SQL (SS2K8) :: Updating Statement Depending On 2 Fields

Sep 30, 2015

I need to build an update query for all my article beginning with '0.%' for my varchar field refkey, but depending on some conditions.

For example.
Case st.base <> '' and st.qttbase <> 0
Theo refkey = B
Case st.cos <>'' and st.qttcos <> 0
Then refkey = C
Case st.refo <> '' and st.qttrefo <> 0
Then refkey = R

But my problem are That i can have Many combination on refkey, for example:

B,BC,BCR,C,CB,CBR,R...and so on.

Also i need to separate the letters with comma, like:

B
B,C
B,C,R
.....

View 6 Replies View Related

How To Split A Field Into Two Fields

Apr 14, 2006

I have the following fields in table A:

GL_ID| Date |GL_Name_VC | Amount Period_TI|Year_SI
===============================================
1000|31/12/2005 | Sales | -8,000.00 | 12 | 2005
===============================================
1000|06/01/2006 | Sales | -6,000.00 | 01 | 2006
===============================================
1000|20/01/2006 | Sales | 2,000.00 | 01 | 2006
===============================================
1000|28/01/2006 | Sales | -4,000.00 | 01 | 2006

The above database is running on Microsoft SQL Server 2000 and i would like to query
for a report that looks something as below:

Period | Date | GL_Name_VC | Debit | Credit| Net Change | Balance
===============================================
01 |01/01/2006|Opening Bal | 0 | 0 | 0 | 8,000
01 |06/01/2006|Sales | 0 | 6,000 | 0 | 0
01 |20/01/2006|Sales | 2,000 | 0 | 0 | 0
01 |28/01/2006|Sales | 0 | 4,000 | 8,000 |6,000


The formula for the above calculated fields are as below:

Opening Balance = carried forward balance from Year 2005
Debit = All positive amount
Credit = All negative amount
Net Change = Total Credit - Total Debit in Period 01
Balance = Total of Net Change + Opening Bal

Guys, hope someone out there can help me with the sql command for the above report?

View 4 Replies View Related

How To Split A Field Into Two Fields

Apr 11, 2006

I have the following fields in table A:

GL_ID| Date |GL_Name_VC | Amount |Period_TI|Year_SI
===============================================================
1000|31/12/2005 | Sales | -8,000.00 | 12 | 2005
===============================================================
1000|06/01/2006 | Sales | -6,000.00 | 01 | 2006
===============================================================
1000|20/01/2006 | Sales | 2,000.00 | 01 | 2006
===============================================================
1000|28/01/2006 | Sales | -4,000.00 | 01 | 2006

The above database is running on Microsoft SQL Server 2000 and i would like to query
for a report that looks something as below:

Period | Date | GL_Name_VC | Debit | Credit| Net Change | Balance
=====================================================================
01 |01/01/2006|Opening Bal | 0 | 0 | 0 | 8,000
01 |06/01/2006|Sales | 0 | 6,000 | 0 | 0
01 |20/01/2006|Sales | 2,000 | 0 | 0 | 0
01 |28/01/2006|Sales | 0 | 4,000 | 8,000 |16,000


The formula for the above calculated fields are as below:

Opening Balance = carried forward balance from Year 2005
Debit = All positive amount
Credit = All negative amount
Net Change = Total Credit - Total Debit in Period 01
Balance = Total of Net Change + Opening Bal

Guys, hope someone out there can help me with the sql command for the above report?

View 2 Replies View Related

Insert Identity Depending On The Value Of A Column

Apr 23, 2008

Would like to have Identity Inserted wrt a date column
Eg:
ProdDate ID Details
============================
2008.04.01 1 afafafaf
2008.04.01 2 GAFSGHFGF
2008.04.02 1 GAGJAGSDH
2008.04.02 2 QYTYTT
2008.04.03 3 QYTWRRT

At present it is not an Auto increment , I check for the Maximum ID and add One to the next Inserted record. Is there any simpler method?

View 13 Replies View Related

How To Sum A Column Depending Of Another Colum Into Different Vars?

May 20, 2006

Hi all, I am trying to sum a column into different variables depending on another column. Let me explain my self better with an example

DECLARE @Initial decimal(18,2), @incomings decimal(18,2), @outgoings decimal(18,2)

SELECT
@initial = CASE WHEN type = 1 THEN SUM(amount) END,
@incomings = CASE WHEN type = 2 THEN SUM(amount) END,
@outgoings = CASE WHEN type = 3 THEN SUM(amount) END,
FROM Transactions
WHERE date = '05/14/2006' AND STATION = 'apuyinc'
GROUP BY type, amount

What I am trying to do is to sum all of the incomings transactions into @incomings, all of the outgoing transactions into @outgoings and the initial transaction into @initial where
The incoming transactions is type 2,
outgoing transactions is type 3

Thanks for the help


@puy

View 5 Replies View Related

Number Of Rows Depending On A Column Value

Sep 26, 2007



Hi all,
I have a table with artikels and count, sample:

Art Count
------------
12A 3
54G 2
54A 4

I would like to query this table and for each 'count' retrieve one row:
query result:

Art Count
------------
12A 3
12A 3
12A 3
54G 2
54G 2
54A 4
54A 4
54A 4
54A 4



Is this possible?

Thanks, Perry

View 3 Replies View Related

UNION With A Max On Split Date/Time Fields

Mar 30, 2000

I have 2 tables, each with one ID field, a separate
Date and Time fields and a number of other fields.
The tables contain duplicates on the ID field.
I want to do a UNION keeping only the record with the latest
Date and Time.

This would work:
SELECT MyTab.myKeyField, Max(MyTab.myDate) AS myDate
FROM (SELECT myKeyField, myDate
from Table1
union
SELECT myKeyField, myDate
from Table2) AS MyTab
GROUP BY MyTab.myKeyField

But is only taking care of Date, not Time (some records have
the same date but different times)
The other problem is, when I add more fields, I have to
include them in the GROUP BY clause, and this way I end up
with duplicates (because some other fields have different
values)

Is there a way to do this?

View 1 Replies View Related

Split Fields And Display Query Result

Mar 21, 2007

Hi,
I'm having a problem in spliting the fields
I need to ru the following query to join two tables and getting the output as shown.

Query:
select cusl.user_name,
pmts.bill_ref_info, pmts.payee_acid, pmts.cust_acid, pmts.txn_amt,pmts.pmt_id
from cusl, pmts
where cusl.ubp_user_id = pmts.ubp_user_id and pmts.ubp_user_id= 'testinglive'

Output:
user_name bills_ref_info payee_acid cust_acid txn_amt
SAMEER ALLA0210181#123456#Amita 378902010021095 383702070051411 1.000 16318
SAMEER BARB0GNFCOM#6788990#Vikram Kalsan 378902010021095 383702070051411 1.000 16327
SAMEER BKID0000200#378902010099678#Vikram 378902010021095 383702070051411 1.000 14031
SAMEER undefined#123456789123456#Vikram 378902010021095 383702070051411 1.000 13918


Now I need to display the second field which is a #-separated field as individual fields alongwith tghe other fields that are shown on execution of the query.
Can this be done? Please guide me on this...

View 7 Replies View Related

List Tables Depending If Column Exists

Jul 27, 2004

Hi there,

Is there a quick way to list all the tables in a DB that contain a certain column name?

Thanks

S

View 5 Replies View Related

Trigger To Work Depending On Datatype And Column Name

Jan 24, 2008

Hi,

I have a trigger that fires on update, populating a varchar field [ExampleDate_Str] with the dd/mm/yy format of the inserted datetime field [ExampleDate]. It works, but I don't want to rewrite it for the thousands of datetime fields in hundreds of tables in my db. So I am looking for a way to do something like this in a trigger -

for each column in triggered tableset @ColName = (the column name)if datatype(@ColName) = datetimeset @ColName + "_Str" = convert(varchar(8),ExampleDate,3)next

Obviously the above doesn't work in SQL or indeed any other language yet invented - is it possible to make it so that it does, and if so, how? The main points are to read the column name into a variable, check the datatype, and modify the column named @ColName + "_Str".

Thanks...

View 7 Replies View Related

Integration Services :: SSIS Package To Split Address Into 3 Fields

Jun 10, 2015

I have a table that I am using in a package to create an extract from. In that table is an address field called "Street" that is 255 characters in length. My table also has 3 additional fields called address_1, address_2 and address_3 that are each 50 characters in length because that is the requirement for my extract. I need to split the address field up in such a way that if it is longer than 50 characters, it backs up to the first  space in the address prior to character #50, puts that info in street1, then from that cut off point used in street1, puts the next 50 up to the prior blank space in street2, then the remainder in street3. Where the extract will be used only has three 50 character fields so if the data runs more than 150 characters, the street3 data will just have to be truncated. No way around that, but I don't anticipate any address getting close to that long. Although doing such a split would be much easier using SQL, the solution requirement is that it be done in the package, not using SQL to do so.

I'm assuming I need to use a "derived column transformation" in my data flow. But, I can't figure out how to do what I need to do with a derived column transformation.

Example of info in an address:
123 Chicamauga Avenue South, Across the Street from International Center Square, Apartment Number 17650 Tokiwa-machi  Machida

position 1-50:
123 Chicamauga Avenue South, Across the Street fro

Therefore, Street1 would need to get:
123 Chicamauga Avenue South, Across the Street

[code]....

View 5 Replies View Related

SQL 2012 :: Insert ID Column Value Into Table Depending Upon Input Filename

May 19, 2015

I am loading files with same format from two different locations in to one database. First, my SSIS connects to location 1.

Lets Say
Location1 : C:LoadFilesImport
Location2 : D:LoadFilesImport

Location one has three different set files starting with

First Set: AP_1, AP_2,AP_3,
Second Set: VD_1, VD_2, VD_3,
Third Set: BK_1,BK_2,BK_3,

This SSIS set to run every 3 hours, if it finds files of any set load them. While loading it has to insert into a derivedcolumn called CustID. If the file name Starts with AP_ , custiD values should be as 101

AP_1 goes to Table1
AP_2 goes to Table2
AP_3 goes to Table3

If the file name Starts with VD_ , custiD values should be as 201
If the file name Starts with BK_ , custiD values should be as 301

after processing all these files in first location, the SSIS looks for files in second location and does the same?

--How to achieve CustID depending upon file name ?

View 0 Replies View Related

Set Column Value Depending As % Of Another Column Value (was: Help!!)

May 11, 2007

Hi,
I'm not sure if this can even be done but I will ask anyway.
I have a table that has a sales price field in it. I have another field in that table called commission. The commission is 15% of the sale price. Is there any SQL that will calculate and automatically put that value in it, or only allow you to put the correct value in?
Hope this makes sense and hope someone can help.
Thanks for your time.
Liam
(Using MS SQL by the way)

View 5 Replies View Related

Problem With A Foreing Key

Jul 20, 2005

I'm a beginner in using SQLServer and I 'm trying to bring a db Schemawritten for DB2 into SQLServer.My problem is this: using a tool to translate the script for creating theDB, I obtain the following code:ALTER TABLE PROJECT.RSURETTA ADD FOREIGN KEY(VOCE )REFERENCES PROJECT.RSANVOCE(VOCE ) ON DELETE SET NULL ON UPDATE NO ACTIONBut, when I try to run the script the system says:Incorrect syntax near the keyword 'SET'.Can I assign a null value to an other table with a reference?Thank youFede

View 2 Replies View Related

Replication Foreing Key Problem

Mar 14, 2006

Hi,

I want to replicate in the same Server 2 tables, first I test with the same data datbases in other Server but 1 table and all is ok , when I try to do the same in the production server occurs an error, Distibution Agent Error Details show me this: Could not drop object 'SER_CURRENCY' because it is referenced by a FOREIGN KEY constraint. Like I said first I run a test, in this test I check IDENTITY: YES (Not for replication), ENFORCE RELATIONSHIPS FOR REPLICATION is unchecked.

My scenario is:

- Windows XP, SQL Server 2000 Developer Edition sp4.

Please, I want to know other reason for this error. Thanks



- Neyver.

View 1 Replies View Related

How Many Foreing Keys Does A Table Has?

Dec 12, 2007



hi

I could not build a query using the system tables; where I can know how many foreing keys does a specific table has? I´m lost.

can somebody help me... thanks

View 4 Replies View Related

Split A Column

Nov 4, 2004

Hi everybody

Does any body know how to split a field in a table into two fields

eg
usermaster(table)
userid(field)

usermaster has 40 users with user id 1 to 40
i want to get data as

userid userid
1 21
2 22
3 23
. .
. .
. .
20 40

Thanks you very much

View 3 Replies View Related

Obtaining Foreing Keys Dependences

Jan 6, 2006

I want to know how to obtain the relationships of foreing keys when they have diferent names in diferent tables using SQL querys from VB.net in SQL Server 2000.

Example:

Table Person
------------
IDPerson
Name
Address


Table Customer
--------------
IDCustomer
.
.
.


Table Employee
---------------
IDEmployee
.
.
.


The dependencies are:

IDPerson--->IDCustomer
IDPerson--->IDEmployee

View 2 Replies View Related

How To Split Datetime Column

Aug 3, 2007

I have column that hold datetime , i want to split the column into many columns ex:
column --> 01/01/2007 00:00:00
i want tp split to day month year hour minute second

View 1 Replies View Related

Split Data In Column

Mar 24, 2006

hai all,
This is my first question to this forum.
here is my situtation:
I am into report testing I need to test a report for which i have write a query,iam using qery analyser for runing query


Database : sql server
tabel name :job_allocations
column naME :technicain code

Based on techincain code in joballocation tablei need to get technician cost from other table for the particular technician.

Based on the technician code user chooses column will be updated
if single data will be TC01
if more than one then data will be TC01:TC02:TC03

user can choose any number of techincian for a job

MY problem is :How to split tha when there is multiple technician and calculate cost for the job
Ineed it in single excecution query

Table structure

job_allocation table

jobcardn_fk Technician_code
jc01 TC01
jc02 Tco1:Tco2:Tc03......


I need it in



jobcardno_fk TEchnician_code
jco1 Tc01
jco2 Tc01
jco2 TC02
jc02 Tc03




TKs ands Regards
Diwakar.R

View 1 Replies View Related

Split A Column Into 2 Columns

Jul 23, 2005

Hi everyoneI guess this should be a simple question for the gurusI have a Data in a column which is to be places in 2 columns instead ofone. How do i go about doing it in MS SQL server? Could someone pleasehelp me. I could do it in access with an update query but things are alittle different in SQL server so I am a little lost.Eg.NameJohn?Doeto be split intoName LastNameJohn DoeThanks in advance.Prit

View 6 Replies View Related

Split Column Into Severl Ones

Jan 4, 2008

Hello,

I have a table which contains a column like that:

Comment
-----------------------------------------------------------------------
User: Toto Password: Toto-Toto


I'd like to have in the same table:

Comment User Password
--------------------------------------------------------------------------------------------------------
User: Toto Password: Toto-Toto Toto Toto-Toto

Do you have an idea of how to do it in SSIS?
Thanks a lot for your help.

View 4 Replies View Related

Split Values From Within Column

May 7, 2008


I have been trying to separate firstname,last name,middle from name column

Existing Format
Column Name =FIRST,LAST M

Desired
First
Last
M

I would llike to divide one column into three columns...How can i achieve it..

Please let me know

View 5 Replies View Related

How To Split A Database Column ?

Oct 11, 2007



Hi,

I have a column, for example Prod_ID count is 100 (contains Raw Matl & Finished Matl).

I want to split this 2 columns as

Raw Matl Finished Matl
60 40

Can anyone please help me how to do this in SQL Server.

Thanks in Advance
Rajesh

View 5 Replies View Related

How To Split Three-value Column Into The Same Target?

Mar 21, 2007

Hi everyone,

We've got a source file which owns three different values: 'A','B','M'.

Where 'A' stands for "New Rows" and 'B' for "Delete rows" and 'M' for 'Update rows'

Using Conditional Split task we can redirect each subset into a OLEDB Destination but we are wondering how can we do the same using only one OLEDB? We've got only one table.

Thanks for your input and time,



View 1 Replies View Related

Query Split Column In 2 Columns In SQL

Jan 22, 2008

I like to push 1 column into 2 different columns just to show it on the screen. So no import in another table ore something like that.
I have a table like this:
Select Name from Cars;
Result:
Col1
BMWMercedesFordAudi
But i like to make a query so it is displayed like this:
Col1                Col2
BMW               FordMercedes         Audi
So i can bound a table directly to that column!Is this possible with SQL, and how can i build it.Thanks.

View 1 Replies View Related

Split One Column Into Multiple Columns

Jan 28, 2008

Hi all,
I have a requirement like this  ,
I have Address Column.It is containing data like Mr. K KK Tank Guntur Jal Bhavan, Univercity Road, Rajkot 9843563469
I have to split this into 3 more columns like(Address1,name,phoneno)--
Means i have 4 columns including Address Column.(Address,Address1,name,phoneno)
 
Example:
Address:Rajkot
Address1:Univercity Road
Name:Mr. K KK Tank Guntur Jal Bhavan
PhoneNO:9843563469
 
How can i acheive this one with out data lose in Address Column.
Thanks in advance.
 
 
 

View 2 Replies View Related

Split Data Into Two Column Table

Mar 13, 2007

Hello all,

Little layout question. Assume my dataset returns the following data:

A

B

C

D

E



How can I present this data in a table (or list, or matrix) splitted into two columns:

A B

C D

E



Any idea will be very appreciated! Thanks a lot!

TG

View 4 Replies View Related

Transact SQL :: Split Column Data To Row

May 19, 2015

I found string from net how to split column data to row

SELECT A.JbIDFull, A.ProdID, A.OrderQty, A.OtherDetails, A.OrderDate, c.Item FROM
(SELECT JbIDFull, DeptID, ProdID, OrderQty, OtherDetails, OrderDate, LamORSteachType, JBID, RMIDs, RMQty
FROM tblJobCardforProduction WHERE JBID = '2' AND DeptID = '3') A
CROSS APPLY dbo.SplitStringNEW(a.RMIDs,';') b
CROSS APPLY dbo.SplitStringNEW(a.RMQty,'/') c

When I apply one cross apply it's working fine but when i apply for one more column is replacing three time one row, this data i want to split RMIDs and RMQty with same JbIDFull

JbIDFull   DeptID    ProdID OrderQty     RMIDs RMQty

PD-May15-00001 3 2044 10000     PROD-00052 0
PD-May15-00002 3 921 1000 PROD-00052;PROD-00383;PROD-00384 500;600;700

View 2 Replies View Related

Query To Split A Database Column ?

Aug 3, 2007



How can i write a query to split a database column and shows 2 new columns. In my database column
I have 2 mixing items and need to split out to 2 columns. Normally I have to write a query and change parameter
and run another query.
For example a database column with average number and range number.
Thanks
Daniel

View 16 Replies View Related

Transact SQL :: Split Values In Column

Oct 15, 2015

I've a table that has salescode(124!080) and salesamount(125.65!19.25) and I need to split the columns. Salesman(124) has commission(125.65). Here is the DDL:

USE tempdb;
GO
DECLARE @TEST_DATA TABLE
(
DT_ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED
, InvNoVARCHAR(10) NOT NULL
, SalesCode NCHAR(80) NOT NULL

[code]....

View 11 Replies View Related

How Do I Split A Column Result By A Nonalphanumeric Character?

Jan 24, 2006

I have a column that returns client numbers.
The client numbers are 4-6 characters in length.  A period (.) is added to the end of the client number, and then one last digit (1-4) is affixed at the end to denote a categorization.
In SQL, I need to figure out how to divide these results into two columns, one for the client number and one for the categorization number.
EG:  client #4334.1 would become 4334 for client # and 1 for categorization number
or
         Client #424561.3 would become 424561 for Client # and 3 for categorization number.
I have to strip out the period in the process and leave myself with just the numeric characters divided into two columns.
Ive been researching my brains out on string queries and substring queries and I can't figure out how to parse out the period and/or to have SQL understand that I need everything BEFORE the period for one column and everything AFTER the period for the second.
Is it possible to do this?  I really need help on this one.
Thank you :)

View 4 Replies View Related







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