I have a scenario where I am generating two .CSV files from one .TXT file source.
One of the transformations required is this:
Identify records that contain at least one field with an empty string or NULL value
Send these records to a separate .CSV file destination
I need to check for this condition across multiple fields.
For example I have these fields in my source .TXT file:
col1
col2
col3
col4
col5
col6
col7
I need to check to see if any of these fields contain an empty string or a NULL value.
I am using a Conditional Split Transformation with this formula:
col1 !=""
That works as expected for one column, but not as expected when I try to write the formula for all columns in my text file:
col1 !="" || col2 !=""...
Some rows with an empty or NULL value in one of the fields are ending up in the wrong .CSV file.
Any help is appreciated!
If I have understood your question correctly, I think you just need to use the following formula in a Conditional Split Transformation:
ISNULL(col1) || ISNULL(col2) || ISNULL(col3) || ISNULL(col4) || ISNULL(col5) || ISNULL(col6) || ISNULL(col7) || TRIM(col1) == "" || TRIM(col2) == "" || TRIM(col3) == "" || TRIM(col4) == "" || TRIM(col5) == "" || TRIM(col6) == "" || TRIM(col7) == ""
There is a difference between an empty string and a NULL, although since your source is a .TXT file this might not be so obvious as it would be if your source was a database table.
Here is the SQL Fiddle for the sample data.
Screenshot of the Conditional Split Transformation Editor
Screenshot of the Data Flow results
Hope this helps.
I Figured it out. Used script component before conditional split to flag the rows.
Code:
/* Microsoft SQL Server Integration Services Script Component
* Write scripts using Microsoft Visual C# 2008.
* ScriptMain is the entry point class of the script.*/
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
/**string RecordID = "";
string ClientRequestID = "";
string AccountID = "";
string ClientMemberID = "";
string MemberDOB = "";
string ProviderPhone = "";**/
string Flag = "True";
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
if (Row.ClientRequestID == "" || Row.ClientMemberID == "" || Row.AccountID == "" || Row.MemberDOB == "" || Row.ProviderPhone == "")
{
Flag = "False";
}
else
{
Flag = "True";
}
Row.Flag = Flag;
}
}
Related
I am trying to creating a booking system, and as of now I am going to allow my user to insert their name and then check if there is a value. But whenever I try to simply accomplish this by using if( m == 'string) it thinks that all of the empty spaces are strings which results in everything saying booked.
Function checkifBooked(name)
{
var string ='BOOKED';
var string2 ='FREE';
if(typeof name == 'string')
{
return string;
}
else{
return string2;
}
}
When you get the value of an empty cell you get an empty string '', which is still a string. Thus, your if always evaluates to True.
In javascript, an empty string evaluates to false, so you can test the string directly.
try:
if(name)
Or if you prefer to be more explicit, you could check the type of name, then check it's length.
if(typeof(name) == 'string' && name.length > 0)
I am using Connector C to connect to my MySQL database. A modification that I have made to the database recently now allows the data in my url field to be NULL. Connector C does not appear to have any problems reading the NULL value, but when I try and pass the value to my array structure using strcpy, the program crashes. Here is a simplified version of my code:
mysql_real_connect(conn, server,user,password,database, port, NULL, 0);
mysql_query(conn, "SELECT * FROM main WHERE propType IN ('Single Family', 'Condominium')");
res = mysql_use_result(conn);
while (((row = mysql_fetch_row(res)) != NULL) && (row[0] != NULL)) {
props[count].uniqueID = atol(row[0]);
strcpy(props[count].address, row[1]);
.
.
.
strcpy(props[count].url, row[55]);
count++;
}
By tracing out output of the rows, I have determined that it is this line of code that is failing, and it is ONLY failing when row[55] is (null):
strcpy(props[count].url, row[55]);
I am fairly new to C, and I assume that the problem lies in trying to use strcpy with a null string.
Any suggestions?
As is suggested above in the comment the problem is that row[55] has the value NULL and so strcpy() will crash. Maybe you want to try the following:
if (row[55] != NULL)
strcpy(props[count].url, row[55]);
else
props[count].url[0] = '\0';
Here is another example code which use a bit to store if the database contains NULL or a empty value:
if (row[55] != NULL)
{
strcpy(props[count].url, row[55]);
props[count].urlEmpty = false;
}
else
{
props[count].url = '\0'; // Maybe you can skip this
props[count].urlEmpty = true;
}
In this case you need to expand your structure.
I have a named query below for optional parameter which is flightNumber, departureAirport and arrivalAirport. But this query is not working when I don't give any value for these parameter.
#Query("from CapacityMonitor
where carrierCode = :carrierCode and
(:flightNumber IS NULL OR flightNumber = :flightNumber) and
(:departureAirport IS NULL OR departureAirport = :departureAirport) and
(:arrivalAirport IS NULL OR arrivalAirport = :arrivalAirport)
I can change a query but i have to use with #Query annotation only
So you want to keep your query the way it is and make it work with or without parameters. Well, you can't do that. If the query is expecting parameters, then you have to set them.
The best approach would be to leave the query the same way it is and set the parameters to NULL so that :param IS NULL returns TRUE in those cases and return all results. That way you will fake a match.
Anyway, the parameter has to be set always.
I would suggest using a Criteria Query to build a statement with custom WHERE clause.
Based on your example, it could look like this (depending on your data types):
public List<CapacityMonitor> getFlights(String carrierCode, String flightNumber, String departureAirport, String arrivalAirport) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<CapacityMonitor> query = builder.createQuery(CapacityMonitor.class);
Root<CapacityMonitor> root = query.from(CapacityMonitor.class);
query.select(root);
// Carrier code is mandatory
query.where(builder.equals(root.get("carrierCode"), carrierCode));
// Other properties are optional
if (null != flightNumber && flightNumber.length() > 0) {
query.where(builder.equals(root.get("flightNumber"), flightNumber));
}
// Use LIKE expression to match partially
if (null != departureAirport && departureAirport.length() > 0) {
query.where(builder.like(root.get("departureAirport"), "%" + departureAirport + "%"));
}
if (null != arrivalAirport && arrivalAirport.length() > 0) {
query.where(builder.like(root.get("arrivalAirport"), "%" + arrivalAirport + "%"));
}
return em.createQuery(query).getResultList();
}
I have selected multiple columns from my table, but I don't know how to pass it to my view.
var result = (from f in db.firmware
where f.firmware_release_type_text != ""
|| f.firmware_release_type_text != null
|| f.firmware_release_number_int != 0
select new{
f.firmware_release_type_text,
f.firmware_release_number_int
}).Distinct();
The result is f__anonymous2. I want to some how use it in my view. all the forums have just answered how to choose multiple columns, but nobody mentions how to pass them. I think I'm missing something obvious.
I want to be able to use this fields, or even merge them as one string.
I have tried Cast and so many other options which did not work.
When I try to force casting it sting, I get :
Unable to cast the type 'Anonymous type' to type 'System.String'
Thanks
UPDATE:
At the end I went with:
var result = (from f in db.firmware
where (f.firmware_release_type_text != "")
&& (f.firmware_release_type_text != null)
&& (f.firmware_release_number_int != 0)
select new{
f.firmware_release_type_text,
f.firmware_release_number_int
}
).Distinct();
List<string> result2 = new List<string>();
foreach (var item in result)
{
result2.Add(item.firmware_release_type_text
+ "-" + item.firmware_release_number_int);
}
If you want to return your data as a string you have to say how it should be formatted. You could for example change this:
select new
{
f.firmware_release_type_text , f.firmware_release_number_int
}
To this:
select f.firmware_release_type_text + " v" + (int)f.firmware_release_number_int
You have two options to create a model first, second format the data on the server side.
I have a table (I am using Entity Model) and filtered that table using LINQ query which is working fine.
Now I want to filter the records on the basis of array of dates. I am not able to implement IN clause on array of dates
filteredList = leadsNewAndScheduled.Where(lead =>
(LeadTypeIDs.Contains(lead.TYPE_ID.ToString()) ||
LeadTypeIDs == string.Empty) &&
(priorityIDs.Contains(lead.PRIORITY_ID.ToString()) ||
priorityIDs == string.Empty) &&
(((lead.EXPIRED_ON <= dateExpiry ||
Convert.ToDateTime(lead.EXPIRED_ON) == DateTime.Today.Date) &&
lead.STATUS_ID == (int)Enumerations.LeadStatus.New) ||
lead.STATUS_ID == (int)Enumerations.LeadStatus.Active) &&
(lead.START_TIME IN (arrAppointmentDates))
).ToList();
I want your help in following
(lead.START_TIME IN (arrAppointmentDates))
Thanks in advance.
Use Predicate Builder
Write your query without the date condition like
var query = leadsNewAndScheduled.Where(lead =>
(LeadTypeIDs.Contains(lead.TYPE_ID.ToString()) ||
LeadTypeIDs == string.Empty) && ....
Then write
var predicate = PredicateBuilder.False<Lead>();
foreach (DateTime date in dates)
{
DateTime temp = date;
predicate = predicate.Or (p => p.START_TIME == temp);
}
var result = query.Where(predicate).ToList(); // Don't call ToList() earlier
However please note that if you're using Entity Framework you need to call AsExpandable() on the entity set before applying predicates on it like so:
return objectContext.Products.AsExpandable().Where (predicate);
I solved this problem while declaring list of dates and then applying contains clause in LINQ query.
example:
//list of dates.
List<DateTime> arrAppointmentDates;
//change in query
arrAppointmentDates.Contains(Convert.ToDateTime(lead.START_TIME).Date)