For Each Loop Failure When Some Values In Recordset Are NULL

Sep 15, 2006

I have a for each loop container that is performing various tasks as it loops through a record set. Some of the values from the recordset are NULL at times and this causes the FELC to fail because it is unable to map the variables that have NULL values.

Is there something I can set to have it accept the NULLS or something I can change about the variables themselves. This is valid data that still needs to be processed. There are other attributes that have data in the record.

Here are samples of my error messages:

Error: ForEach Variable Mapping number 19 to variable "User::varTransactionReference" cannot be applied.

Error: ForEach Variable Mapping number 20 to variable "User::varFlowStartDate" cannot be applied.

Error: ForEach Variable Mapping number 26 to variable "User::varCancelFee" cannot be applied.



Thanks in advance.

SK



View 2 Replies


ADVERTISEMENT

Compressing Multiple Rows With Null Values To One Row With Out Null Values After A Pivot Transform

Jan 25, 2008

I have a pivot transform that pivots a batch type. After the pivot, each batch type has its own row with null values for the other batch types that were pivoted. I want to group two fields and max() the remaining batch types so that the multiple rows are displayed on one row. I tried using the aggregate transform, but since the batch type field is a string, the max() function fails in the package. Is there another transform or can I use the aggragate transform another way so that the max() will work on a string?

-- Ryan

View 7 Replies View Related

Recordset Destination And Foreach Loop

Jul 11, 2007

I have a csv file in which I am reading into a recordset destination and want to than use a foreach loop to cycle through those records and do some things. The problem I am having is after defining the variable name of the records set as results, and than going into the foreach loop, choosing collection, using the foreach ado enumerator, i dont see anything in the dropdown under ado object source varable?????? I am new to SSIS but I basically want to parse through this file, change some columns in each line and than either update or insert data in a sql table.

View 4 Replies View Related

Loop Through A Recordset To Populate Columns In A Temp Table

Jul 23, 2005

I want to take the contents from a table of appointments and insert theappointments for any given month into a temp table where all theappointments for each day are inserted into a single row with a columnfor each day of the month.Is there a simple way to do this?I have a recordset that looks like:SELECTa.Date,a.Client --contents: Joe, Frank, Fred, Pete, OscarFROMdbo.tblAppointments aWHEREa.date between ...(first and last day of the selected month)What I want to do is to create a temp table that has 31 columnsto hold appointments and insert into each column any appointments forthe date...CREATE TABLE #Appointments (id int identity, Day1 nvarchar(500), Day2nvarchar(500), Day3 nvarchar(500), etc...)Then loop through the recordset above to insert into Day1, Day 2, Day3,etc. all the appointments for that day, with multiple appointmentsseparated by a comma.INSERT INTO#Appointments(Day1)SELECTa.ClientFROMdbo.tblAppointments aWHEREa.date = (...first day of the month)(LOOP to Day31)The results would look likeDay1 Day2 Day3 ...Row1 Joe, PeteFrank,FredMaybe there's an even better way to handle this sort of situation?Thanks,lq

View 11 Replies View Related

Shredding Recordset Object Var In ForEach Loop (problem)

Feb 14, 2006

I have a package that starts by loading a recordset into an object variable. The recordset is then enumerated with a ForEach loop. The loop sets some string variables. Within the loop container I have a Script task that uses a MsgBox to show the results for testing purposes. The package uses checkpoint restart (if that matters?).

The first time I run the package the 1st record is displayed in the MsgBox, then the 2nd, but then the loop is stuck on the 2nd record forever. I break the run, and when I rerun it the 1st record is displayed followed by each subsequent record correctly and the package completes successfully. Now, if I were to run again the same problem would occur on rec 2 and I would have to break the run, and then the next run everything would work fine.

Why does the script get caught in an infinite loop the first time it's run, but works fine when restarting from the checkpoint?

Here's my relevant code:





ForEach: Enumerator=ADO Enumerator, Enumeration Mode=Rows in first table




Public Sub Main()
Dts.Variables("User::SQL1").Value = "SELECT src.* FROM " & Trim(Dts.Variables("User::Src1Tbl").Value.ToString)
MsgBox("sql=" & Dts.Variables("User::SQL1").Value.ToString)
Dts.TaskResult = Dts.Results.Success
End Sub

View 8 Replies View Related

Recordset Destination With Foreach Loop Container - Finding Indexes

Mar 3, 2006



I'm curious to know how other people are handling the Recordset Destination in to be processed by a Foreach Loop Container. It seems a little odd to me that you can only map the parameters by knowing the index of the columns of the Recordset, however, the order that you built the recordset destination doesnt stay the same. I've been debugging for a while to find out that after I saved my recordset destination the order of the fields changed. To some order without a clear logic. I'm going to guess it might be the lineage id.

The bigger problem was this was a really large record set with 60 or so columns. To try and debug the problem of finding the indexes, I had added a Multicast tranform and saved the output to an Excel Destination. Of course, the order I setup the Excel file was the order I got the fields. Why would this not be the case with the Recordset Destination?

View 4 Replies View Related

Foreach Loop With XML Source Failure

Oct 25, 2006

I can't import from XML files using a foreach loop. I load an XML file with a generated XSD. When I map the file to the table it has no errors. If I now go back and change to a different XML file, I get an error:

"Error 1 Validation error. Data Flow Task: DTS.Pipeline: input column "COLUMNNAME" (129) has lineage ID 2115 that was not previously used in the Data Flow task. Package.dtsx 0 0"

This is for testing purposes. When I run the foreach loop it does not work. Ironically, I do the exact same thing in another foreach loop with a completely different XML and it works fine.

Here is the broken XSD:

<?xml version="1.0"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="ComputerStatus">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="computer">
<xs:complexType>
<xs:attribute name="GUID" type="xs:string" use="optional" />
<xs:attribute name="WSUSServer" type="xs:string" use="optional" />
<xs:attribute name="WSUSGroup" type="xs:string" use="optional" />
<xs:attribute name="computerName" type="xs:string" use="optional" />
<xs:attribute name="OSBuild" type="xs:unsignedShort" use="optional" />
<xs:attribute name="OSSP" type="xs:unsignedByte" use="optional" />
<xs:attribute name="Model" type="xs:string" use="optional" />
<xs:attribute name="Make" type="xs:string" use="optional" />
<xs:attribute name="BIOS" type="xs:string" use="optional" />
<xs:attribute name="Processor" type="xs:string" use="optional" />
<xs:attribute name="LastReportedStatus" type="xs:string" use="optional" />
<xs:attribute name="LastSyncTime" type="xs:string" use="optional" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Help. Please. What have I done wrong. I imagine there is a flaw in my XML, but I can't pinpoint it.

Here is a sample of the XML file:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<ComputerStatus>
<computerCount QTY="1" />
<computer GUID="edc2b6a5-5d86-467c-8c89-43fa18ae5921" WSUSServer="WSUS" WSUSGroup="THIS" computerName="COMPUTER" OSBuild="3790" OSSP="1" Model="COMPUTERTYPE" Make="HP" BIOS="1" Processor="x86" LastReportedStatus="10/25/2006 12:00:49 PM" LastSyncTime="10/25/2006 11:57:09 AM" />
</ComputerStatus>

View 2 Replies View Related

Insert Failure While Using ForEach Loop + Execute SQL Task.

Sep 10, 2007

Hello All

I was trying to insert some row from one table to another of different database.
I was using Execute SQL task along with Foreach loop container.

In my execute SQL task I am using this query


SET IDENTITY_INSERT dbo.Table1 ON

INSERT INTO dbo.Table1

SELECT * FROM DB2.dbo.Table2
WHERE TableKey = ?

When executed I get this error:
failed with the following error: "Syntax error, permission violation, or other nonspecific error". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

While the same query when executed in Management Studio Its successful.

The properties I set

For Each Loop Editor Settings:
1) Collection: a) Enumerator Set to ForEach ADO Enumerator
b) ADO Object Source Variable: User:bjectVariablename
c) Checked Rows in the first table
2) Variable Mapping: New Int Variable2 and Index = 0 to set it to first colunm.
3) Expression: Left blank

Execute SQL Task Editor:
1) General: a) Timeout : 0
b) CodePage: 1252
c) Result Set: None
d) SQLSourceType: Directinput
e) SQL Statement: SET IDENTITY_INSERT dbo.Table1 ON INSERT INTO dbo.Table1 SELECT * FROM DB2.dbo.Table2 WHERE TableKey = ?
f) BypassPrepare: False
2)Parameter Mapping: Variable Name : New Integer variable2 selected
Direction: Input
DataType: Long
ParameterName: 0


Can somebody help me in this regards.




Reference:
a) http://www.whiteknighttechnology.com/cs/blogs/brian_knight/archive/2006/03/03/126.aspx



View 10 Replies View Related

XML Task In For Loop Container Always Fails After Initial Failure

Jun 4, 2007

Hi,

I am using an XML task for validating the XML data against the XML Schema. Let me describe the scenario, I am working on.

I have XML Files with different schema. I have different XSD files for each XML file type. I have used a for loop container which has a script task and an XML task. Script task gets the XML File and XSD file contents into variables which are, in turn, used by XML Task for validation.

XML task is configured in the option "Validate". I have provided the XML Data in variable and XSD file content in other variable. XML Task stored the result in another variable. FailOnValidationFail property set to false.

Every thing works fine until result of XML Task is false. If XML Task fails for one of the files, it fails for each subsequent files. If first file does not compile to schema and other files do, then XML task fails all the files because first file failed.

Is this a problem with XML Task or I have missed any property. Please, guide me through.

View 3 Replies View Related

Foreach Loop .. Renaming Files On Success And Failure ?? Where ? How?

Feb 23, 2008

ummm. sorry, I've read and seen the tutorials but somehow and missing this.

I have a foreach container. Inside a dataflow task, with an XML source, a data conversion (cause of urrr UNICODE) and and an ole DB data source.

By design (and for this simple example), I get a volation if I attempt to load loads with out deleting entries from my table. No biggie, I would just like this simple package to rename my file to extension .good or .bad depending on success of each loop.
Where and what do I need for this?

Thank you for any help or information!

View 3 Replies View Related

Retrieve A Recordset From One Table Based On The CSV Values In The Field Of Another

Feb 6, 2007

Hello!

I have 2 tables, one that contains a set of codes and their definitions, and another where each record has a field that contains several of these codes separated by commas:

Tab1

SubCode | Definition
---------------
S100 | Def of S100
S101 | Def of S101
S102 | Def of S102

Tab2

DepID | Purpcode |SubCodes
-----------------------------
1 | P100 | S100,S101,S102
1 | P101 | S100, S101
2 | P101 | S100,S102

I'm trying to create a query against Tab1 so that it retrieves a recordset of Subcodes and definitions based on the contents of the Subcodes field for a record in Tab2. I've tried this using a subquery, as follows:

SELECT SubCode ,Definition
FROM Tab1
WHERE SubjectCode IN
(SELECT CHAR(39) + REPLACE(SubjectCodes, CHAR(44), CHAR(39 + CHAR(44)+ CHAR(39)) + CHAR(39)
FROM Tab2
WHERE DepID = 1 AND PurposeCode = 'P101')

The subquery will return: 'S100','S101' and I expect the final recordset to be:

SubCode | Definition
---------------
S100 | Def of S100
S101 | Def of S101

However, it's not returning any records. If I execute the subquery separately and then plug its results into the main query e.g.

SELECT SubCode ,Definition
FROM Tab1
WHERE SubjectCode IN ('S100','S101')

it returns the expected recordset. Does anyone have any pointers? It's driving me nuts..

Cheers
Greg

Complete DDL, Sample Data, and Query below:


if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SubjectCodeDefinition]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[SubjectCodeDefinition]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[DepartmentReturn]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[DepartmentReturn]
GO

CREATE TABLE [dbo].[SubjectCodeDefinition] (
[SubjectCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Definition] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[DepartmentReturn] (
[DeptID] [int] NULL ,
[PurposeCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[SubjectCodes] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
) ON [PRIMARY]
GO

INSERT INTO SubjectCodeDefinition(SubjectCode, Definition)
SELECT 'S100', 'Definition of Code S100' UNION ALL
SELECT 'S101', 'Definition of Code S101' UNION ALL
SELECT 'S102', 'Definition of Code S102' UNION ALL
SELECT 'S103', 'Definition of Code S103' UNION ALL
SELECT 'S104', 'Definition of Code S104' UNION ALL
SELECT 'S105', 'Definition of Code S105'
GO

INSERT INTO DepartmentReturn(DeptID,PurposeCode,SubjectCodes)
SELECT 1,'P100','S100,S101,S104' UNION ALL
SELECT 1,'P101','S102,S103' UNION ALL
SELECT 1,'P102','S100,S101,S105' UNION ALL
SELECT 2,'P100','S100,S101,S104,S105' UNION ALL
SELECT 2,'P103','S103,S104,S105' UNION ALL
SELECT 3,'P100','S100,S102,S104'
GO

SELECT SubjectCode ,Definition
FROM SubjectCodeDefinition
WHERE SubjectCode IN
(SELECT CHAR(39) + REPLACE(SubjectCodes, CHAR(44), CHAR(39)+ CHAR(44)+ CHAR(39)) + CHAR(39)
FROM DepartmentReturn
WHERE DeptID = 1 AND PurposeCode = 'P102')

View 1 Replies View Related

NULL Values Returned When Reading Values From A Text File Using Data Reader.

Feb 23, 2007

I have a DTSX package which reads values from a fixed-length text file using a data reader and writes some of the column values from the file to an Oracle table. We have used this DTSX several times without incident but recently the process started inserting NULL values for some of the columns when there was a valid value in the source file. If we extract some of the rows from the source file into a smaller file (i.e 10 rows which incorrectly returned NULLs) and run them through the same package they write the correct values to the table, but running the complete file again results in the NULL values error. As well, if we rerun the same file multiple times the incidence of NULL values varies slightly and does not always seem to impact the same rows. I tried outputting data to a log file to see if I can determine what happens and no error messages are returned but it seems to be the case that the NULL values occur after pulling in the data via a Data Reader. Has anyone seen anything like this before or does anyone have a suggestion on how to try and get some additional debugging information around this error?

View 12 Replies View Related

Failure On Null Aggregation

Dec 20, 2007

Hi all,

my package is failing every now and then on the following error:

SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x00040EDA Description: "Warning: Null value is eliminated by an aggregate or other SET operation.".
yes, I do have a null aggregation, but in all my tests this didn't cause a failure...
anyone had experience with this?

Thanks.

View 13 Replies View Related

Integration Services :: SSIS Reads Nvarchar Values As Null When Excel Column Includes Decimal And String Values

Dec 9, 2013

I have SQL Server 2012 SSIS. I have Excel source and OLE DB Destination.I have problem with importing CustomerSales column.CustomerSales values like 1000.00,2000.10,3000.30,NotAvailable.So I have decimal values and nvarchar mixed in on Excel column. This is requirement for solution.However SSIS reads only numeric values correctly and nvarchar values are set as Null. Why?

CREATE TABLE [dbo].[Import_CustomerSales](
 [CustomerId] [nvarchar](50) NULL,
 [CustomeName] [nvarchar](50) NULL,
 [CustomerSales] [nvarchar](50) NULL
) ON [PRIMARY]

View 5 Replies View Related

Null Values For Datetime Values Converted To '0001-01-01'

Mar 29, 2006

Hi

can somebody explain me how I can assign a NULL value to a datetime type field in the script transformation editor in a data flow task.
In the script hereunder, Row.Datum1_IsNull is true, but still Row.OutputDatum1 will be assigned a value '0001-01-01' which generates an error (not a valid datetime). All alternatives known to me (CDate("") or Convert.ToDateTime("") or Convert.ToDateTime(System.DBNull.Value)) were not successful.
Leaving out the ELSE clause generates following error: Error: Year, Month, and Day parameters describe an un-representable DateTime.




If Not Row.Datum1_IsNull Then

Row.OutputDatum1 = Row.Datum1

Else

Row.OutputDatum1 = CDate(System.Convert.DBNull)

End If



Any help welcome.

View 1 Replies View Related

Send Mail Task Problem Using A Combination Of ForEach Loop, Recordset Destination, Execute SQL Task And Script Task

Jun 21, 2007

OK. I give up and need help. Hopefully it's something minor ...



I have a dataflow which returns email addresses to a recordset.

I pass this recordset into a ForEachLoop configuring the enumerator as (Foreach ADO Enumerator). I also map the email address as a variable with index 0.



I then have a Execute SQL task which receives this email address as a varchar variable (parameter 0) which I then use in my SQL command to limit the rows returned. I have commented out the where clause and returned all rows regardless of email address to try to troubleshoot this problem. In either event, I then use a resultset to store the query result of type object and result name 0.



I then pass this resultset into a script variable to start parsing the sql rows returned as type object. ( I assume this is the correct way to do this from other prior posts ...).



The script appears to throw an exception at the following line. I assume it's because I'm either not passing in the values properly or the query doesn't return anything. However, I am certain the query works as it executes just fine at the command prompt.



Try

ds = CType(Dts.Variables("VP_EMAIL_RESULTS_RS").Value, DataSet)



My intent is to email the query results to each email address with the following type of data by passing the parsed data from the script to a send mail task. Email works fine and sends out messages but the content is empty. I pass the parsed data as string values to the messagesource and define the messagesourcetype as a variable in the mail task.



part number leadtime

x 5

y 9

....



Does anyone have any idea what I might be doing wrong?

thanks

John

View 5 Replies View Related

SQLCommand's Transaction Property Goes Null On Failure

Sep 20, 2007

I've written some provider independent code that dynamically generates and loads DbCommands with data via Parameters and executes them within a transaction. Everything works fine until an exception occurs and then the DbCommand.Transaction property that was set goes to null,  effectively killing any chance of rolling back the transaction. I've noticed this only happens when the executed command is of type SqlCommand. The OracleCommand mainitains its link to the set transaction of failure. Upon further investigation, I found that this only occurs when parameters are used but not if I dynamically generate the insert statement as a string.. For instance:SqlConnection conn = new SqlConnection(connectionString);conn.Open();SqlTransaction transaction = conn.BeginTransaction();SqlCommand comm = new SqlCommand();comm.Connection = conn;comm.Transaction = transaction; command.commandText = "INSERT INTO Table1 Values (1, 2, 3)";command.ExecuteNonQuery(); If I execute that and it fails the command.Transaction property will remain set to transaction, but in this scenario: SqlConnection conn = new SqlConnection(connectionString);conn.Open();SqlTransaction transaction = conn.BeginTransaction();SqlCommand comm = new SqlCommand();comm.Connection = conn;comm.Transaction = transaction; comm.commandText = "INSERT INTO Table1 Values (@Col1,@Col2, @Col3)";comm.Parameters.add(new SqlParameter("@Col1", 1); comm.Parameters.add(new SqlParameter("@Col2", 2);comm.Parameters.add(new SqlParameter("@Col3", 3); comm.ExecuteNonQuery(); Upon failing the comm.Transaction property gets somehow goes null and the Connection property of the transaction object also goes null.Any ideas on why this only happens with a SqlCommand but no other DbCommand?      

View 4 Replies View Related

Data Conversion - NULL Datetime Causes Failure

Jul 9, 2007

Hi,



I have a flat file source and am bringing it into an OLE DB Destination connected to a SQL Server 2005 database. Since I am bringing in the data via a flat file, I have a conversion step in the data flow, which uses a "Data Conversion" transformation to convert each column to the appropriate destination data type.



When I run my SSIS package, if the datetime column in the flatfile is NULL, then the Data Conversion step fails. I have my Data COnversion step set to redirect error rows to an error output. So, I get all the rows with populated datetime values in the intended destination, and none of the rows with null datetime values (these go to the error destination.)



This is a problem! I need to make sure all valid rows fall through. It seems very odd to me that a NULL datetime could not be converted to a datetime data type. This makes no sense, since a datetime column can naturally hold NULL, just like any other type. So, my question is: is this a bug??? It seems to me it is. I can't believe this would be the desired behavior?!



Microsoft: please let us know whether this is expected behavior. If so, then what would the desired workaround be?



Thanks

View 5 Replies View Related

Use Order By But Want NULL Values As High Values

Nov 9, 2000

Hi,

My query "select blah, blah, rank from tablewithscores" will return results that can legitimately hold nulls in the rank column. I want to order on the rank column, but those nulls should appear at the bottom of the list

e.g.

Rank Blah Blah
1 - -
2 - -
3 - -
NULL - -
NULL - -

At present the NULLs are at the top of the list, but I do not want my ranking in descending order. Any suggestions?

Thanks
Dan

View 1 Replies View Related

Collecting Values Into A Variable In A Loop

Mar 13, 2006

Dear All,

I’m trying to collect values from a query into a single variable within a loop, like so:

WHILE condition is true
BEGIN

SET @intLoop = @intLoop + 1

@myString = @myString + ‘, ‘ + (SELECT companyName FROM @tblTheseComp WHERE id = @intLoop

END

For some reason though the @myString does not collect up the values, but will equal NULL at the end of the loop.

If however I simple do

WHILE condition is true
BEGIN

SET @intLoop = @intLoop + 1

@myString = (SELECT companyName FROM @tblTheseComp WHERE id = @intLoop
END


Then I get the last value from the query as expected.

Can anyone explain why this might be?

Thanks in advance!

View 7 Replies View Related

Integration Services :: SSIS Package - Replacing Null Values In One Column With Values From Another Column

Sep 3, 2015

I have an SSIS package that imports data from an Excel file, replaces any value in Excel that reads "NULL" to "", then writes the data to a couple of databases.

What I have discovered today, is I have two columns of dates, an admit date and discharge date column, and what I need to do is anywhere I have a null value in the discharge date column, I have to replace it with the value in the admit date column. 

I have searched around online and tried a few things using the Replace funtion in Derived columns but no dice so far. 

View 3 Replies View Related

Problem With Setting Variable Values In A Loop

Sep 11, 2007

In a stored procedure that I'm fixing, there is a problem with assigning variable values inside a loop. The proc is using dynamic SQL and if statements to build all these statements, but I'm having to add a new variable value to it that is throwing it out of whack.

This is the current structure:

SET @MktNbr = 10

WHILE @MktNbr < 90

BEGIN

DECLARE@sqlstmt varchar(1000)

SET @Market = '0' + CONVERT(char(2),@MktNbr)

SET @sqlstmt = 'SELECT (columns)
INTO dbo.table' + @Market + '
FROM #table
WHERE marketcode = ''' + @Market + '''
IF @MktNbr = 50
BEGIN
SET @MktNbr = 51
END
ELSE
IF @MktNbr = 51
BEGIN
SET @MktNbr = 52
END
ELSE
IF @MktNbr = 52
BEGIN
SET @MktNbr = 55
END
ELSE
IF @MktNbr = 55
BEGIN
SET @MktNbr = 60
END
ELSE
BEGIN
SET @MktNbr = @MktNbr + 10
END
EXEC (@sqlstmt)


END


I'm probably having a blonde moment, but I'm trying to replace the if statements with this:

SET @MktNbr =
CASE
WHEN @MktNbr = 10 THEN 20
WHEN @MktNbr = 20 THEN 30
WHEN @MktNbr = 30 THEN 40
WHEN @MktNbr = 40 THEN 50
WHEN @MktNbr = 50 THEN 51
WHEN @MktNbr = 51 THEN 52
WHEN @MktNbr = 52 THEN 55
WHEN @MktNbr = 55 THEN 60
WHEN @MktNbr = 60 THEN 70
WHEN @MktNbr = 70 THEN 80
WHEN @MktNbr = 80 THEN 81
ELSE @MktNbr END

Clearly it's wrong because the proc bombs every time with a duplicate table error.

It has been suggested to me that I should hold these market values in an external table. This sounds reasonable but I'm ashamed to admit that I don't know how I'd implement that. Can someone maybe give me a nudge in the right direction?

View 14 Replies View Related

Assigning Variable Values Via Loop Using Different Datatypes

Apr 10, 2008

Hi all,

I need some help regarding a conversion in a Script Task.

I am reading my variable values from a database with a sql task, the table has two columns, variable and variableValue.
Looping through the recordset and setting the different variables works well, with two links:
http://blogs.conchango.com/jamiethomson/archive/2005/02/09/SSIS_3A00_-Writing-to-a-variable-from-a-script-task.aspx
http://sqlblog.com/blogs/andy_leonard/archive/2007/10/14/ssis-design-pattern-read-a-dataset-from-variable-in-a-script-task.aspx

setting the variable value only works well if the package variable is defined as string, because the db field is a varchar, trying to assign an integer for example brings up an error.

Therefor I tried something like CType:
Dts.Variables("MyVar").Value = CType(MyRecordsetField,String), where the target datatype should be depending on the variable datatype instead of being assigned as a constant.

Could someone give me a hint to handle this?

Thanks in advice!

Cheers
Markus

View 3 Replies View Related

WHILE Statement To Loop Through A Table And Get The IDENT_CURRENT Values As It Inserts

Aug 14, 2007



Hi

I have a SSIS package that imports data into a staging table from an excel sheet (This works fine). From the staging tabler i want it to insert the values into my members table, take that unique indentityID that gets created and insert the other values into other tables for that member that was just created.

In the staging table, i have all the values for a single member. But the structure of the database needs all the values inserted into seperate tables. There is no conditions ID in my members table, so the member first has to be created and from there i need to use the newly created member's MemberID and insert the conditions into a seperate table using the MemberID

I have created some sample data that can be used. I think i have an idea of how to do it, but i'm not totally sure if it will work that way, i have however included it in the sample data.





Code Snippet
DECLARE @ImportedStagingData TABLE
(
ID INT IDENTITY(1,1),
Name VARCHAR(50),
Surname VARCHAR(50),
Email VARCHAR(50),
[Chronic Heart Failure] INT,
[Colon Cancer] INT
)
INSERT INTO @ImportedStagingData VALUES ('Carel', 'Greaves', 'CarelG@Email.com', 1,0)
INSERT INTO @ImportedStagingData VALUES ('Jamie', 'Jameson', 'JamieJ@Email.com', 1,1)
INSERT INTO @ImportedStagingData VALUES ('Sarah', 'Bolls', 'SarahB@Email.com', 0,1)
INSERT INTO @ImportedStagingData VALUES ('Bells', 'Scotch', 'BellsS@Email.com', 1,1)
INSERT INTO @ImportedStagingData VALUES ('Stroh', 'Rum', 'StrohR@Email.com', 0,0)
DECLARE @Conditions TABLE
(
ID INT IDENTITY(1,1),
Condition VARCHAR(50)
)
INSERT INTO @Conditions VALUES ('Chronic Heart Failure')
INSERT INTO @Conditions VALUES ('Colon Cancer')
DECLARE @Members TABLE
(
MemberID INT IDENTITY(1,1),
Name VARCHAR(50),
Surname VARCHAR(50),
Email VARCHAR(50)
)
DECLARE @memConditions TABLE
(
MemberID INT,
ConditionID INT
)
SELECT * FROM @ImportedStagingData
SELECT * FROM @Conditions
SELECT * FROM @Members
SELECT * FROM @memConditions
/* --- This is the part that i am battling with ---
DECLARE @CurrentValue INT
DECLARE @numValues INT
SET @numValues = (SELECT COUNT(ID) FROM @ImportedStagingData)
WHILE @numValues <> 0
BEGIN
INSERT INTO @Members
SELECT Name, surname, email
FROM @ImportedStagingData
GO
SET @CurrentValue = (SELECT IDENT_CURRENT('@ImportedStagingData'))
INSERT INTO @memConditions (MemberID), (ConditionID)
VALUES (@CurrentValue, --ConditionValue from @ImportedStagingData, all the values that have a 1)

@numValues = @numValues - 1
END
END
*/






All help will be greatly appreciated.

Kind Regards
Carel Greaves

View 5 Replies View Related

Calculate Total Tuition By Accumulating Column Values ( Loop?)

Jun 3, 2004

I am trying to create a procedure which will calculate the total tuition
This process involves 3 tables.
Contract table has tuition information which is all $100 (set price).
Discount table has discount type and discount percentage (ex. 0.3) on each discount type.
ContractDiscount table have contract number and discount number to connect both tables


I think I need to create a loop since some contract gets more than one discount.
I have to calculate and get result nee to be like this

total_tuition = (tuition - discountPer * tuition) - this has to be a loop condition

Do you have any suggestion ?

Thanks

View 3 Replies View Related

Integration Services :: For Each Loop - Place Full Set Of Values For Every Date In The Year

Jun 15, 2015

I have a table with 3000 values and What I need to do is place a full set of these values for every date in the year 2015. How to achieve this through SSIS?I know we can achieve through SQL using while loop.

EG: 1-1-2015  a b c d 
       1-2-2015 a b c d  like wise 12-31-2015 a b c d .

How to create the package.

View 8 Replies View Related

Using NOT IN With Null Values

May 19, 2008

Hi, I ve a table,  I want to fetch certain rows based on the value of a Column. That column is nullable, and contains NULL values.I used the following query,SELECT Col_A FROM TABLE1 WHERE SOME_ID = 1317 AND Col_B NOT IN (8,9) Here,  Col_B contains NULL values too. I need to fetch all rows where Col_B is not 8 or 9.Now, if I use "NOT IN", it does not work. I tried reading on it and got to know why it does not work. Even "NOT EXISTS" does not help. But still I've to fetch my values. How do I do that?Thanks & Regards,Jahanzeb        

View 6 Replies View Related

SQL Null Values In VB

Apr 10, 2006

I have tried doing a search, as I figured this would be a common problem, but I wasn't able to find anything.  I know that my SP is functional because when I use VWD execute the query outside of the webpage, I get the correct results -however I have to ensure that a field is either entered, or set to <NULL>.  In my SET's I want it to use the wildcards.
What I want is to do a search (plenty of existing topics on that, however none were of help to me).  If a field is entered, then it is included in the search.  Otherwise it should be ignored.  In my VB I have the standard stored procedure call, passing in values to all of the parameters in the stored proc below:
CREATE PROCEDURE dbo.SearchDog@tagnum int,@ownername varchar(50), @mailaddress varchar(50),@address2 varchar(50),@city varchar(50),@telephone varchar(50),@doggender varchar(50),@dogbreed varchar(50),@dogage varchar(50),@dogcolour varchar(50),@dogname varchar(50),@applicationdate varchar(50)AS IF @tagnum=-1  SET @tagnum=NULL  SET @ownername = '%'+@ownername+'%'  SET @mailaddress = '%'+@mailaddress+'%'  SET @address2='%'+@address2+'%'  SET @city = '%'+@city+'%'  SET @telephone='%'+@telephone+'%'  SET @dogcolour='%'+@dogcolour+'%'  SET @dogbreed='%'+@dogbreed+'%'  SET @dogage='%'+@dogage+'%'  SET @doggender='%'+@doggender+'%'  SET @dogname='%'+@dogname+'%'  SET @applicationdate='%'+@applicationdate+'%'
 SELECT DISTINCT  * FROM DogRegistry WHERE (  TagNum = @tagnum OR  OwnerName LIKE @ownername OR  MailAddress LIKE @mailaddress OR  Address2 LIKE @address2 OR  City LIKE @city OR  Telephone LIKE @telephone OR  DogGender LIKE @doggender OR  DogBreed LIKE @dogbreed OR  DogAge LIKE @dogage OR  DogColour LIKE @dogcolour OR  DogName LIKE @dogname OR  ApplicationDate LIKE @applicationdate  ) AND TagNum > 0GO
I don't know why it is creating links inside my SP -ignore them.  TagNum is the primary key, if that makes a difference.
On the webpage, it ONLY works when every field has been filled (and then it will only return 1 row, as it should, given the data entered).  Debugging has shown that when nothing is entered it passes "".
Any ideas?

View 9 Replies View Related

Null Values

Jun 29, 2000

I am trying to retrieve data from two different tables. One of the tables has more than 20 columns some of which are null. I would like to retrieve data from both tables excluding the columns which have null values. How do I do this?

View 3 Replies View Related

SUM When There Are Null Values.

Nov 2, 2007

Would this take care of null values in either a.asset or b.asset?

SELECT convert(decimal(15,1),(sum(isnull(a.asset,0))/1000.0)+(sum(isnull(b.asset,0))/1000.0)) as total_assets

What's throwing me off is that there are multiple a.asset or b.asset for each unique ID. It seems to work, but I'm not following the logic too well. If I were doing this in another language, I would loop through, summing a.asset and b.asset wherever it's not null for each unique ID.

View 8 Replies View Related

Null Values

Jan 16, 2006

Hi,

How can I use "Derived Column" to check if a Datetime value is null or not and if null to insert  00/00/00 instead. ?

The background being that while using a "Derived Column" to change a Column from a (DT_DATE) to a (DT_DBTIMESTAMP) everytime I get a null value it see's it as a error.

And the column in particular has ~ 37 K blank / null fields so Im getting a lot of errors

So far I have tried to use something like

ISNULL([Column 34])

Or

SELECT ISNULL(ID, '00/00/0000') FROM [Column 34]

Or


SELECT ISNULL(au_id, '00/00/0000 00:00') AS ssn
FROM [Column 34

but none seems to work [Column 34] being the offending column.

What a normally use is just a simple "(DT_DBTIMESTAMP)[Column 34]"
in the expression column, which seems to work well, but here I get alot of errors

Any ideas?

View 2 Replies View Related

Null Values

Apr 20, 2007

I set up a new SQL database file, in that file I allowed nulls, When I went through code to save the record, the exception is saying it doesnt allow nulls.



Before I get to involved with SQL, is it a bad practice to use nulls?



If it is what do you enter in place of the null value,

which will lead to more code, right?



Davids Learning SQL

View 13 Replies View Related

Dealing With Null Values

Jul 31, 2006

hi ive got a inert sub where i grab values from text boxes etxthe values are passed to a stored procedure however , one of these fields is a date field , but the field is not required ...so on this line if the date text box is left blank i get an error , not a valid date    .Parameters.Add("@actiondate", SqlDbType.DateTime).Value = txtActionDate.Texti have tried ( the actiondate field can take nulls ..)if txtActionDate="" then    .Parameters.Add("@actiondate", SqlDbType.DateTime).Value = nothing else.Parameters.Add("@actiondate", SqlDbType.DateTime).Value = txtActionDate.Textend if but this doesnt workwhat is the best way of allowing blank values to be passed to the stored procedure( it doesnt fall over with normal text / varchar fields ) thanks

View 1 Replies View Related







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