Showing posts with label columns. Show all posts
Showing posts with label columns. Show all posts

Friday, March 23, 2012

R

How do i replace that character in a derived column ?

Some rows have that character in one or more columns. If i just write this

column == "" ? Unknown : column

where the character is inside "" (can't write it here) the task will just succes without ever doing anything. The output says something like "the dataflow task had no tasks.....", which seems like a bug.

Use a conditional statement.

If [column] contains this value, replace it with another, else leave the value alone:

[column] == "A" ? "B" : [column]|||

i know but it's not a common character. Look at the Subject of this question!!!

It's a square character -> <-

It's a non XML valid character

|||

I think thats a new line character.

If you are using an OLEDB source for your data, you can just do a trim() on the column to get rid of it.

|||

If you know the Unicode character value for it, you can use an escape sequence:

"\xhhhh"

where hhhh is the Unicode character value.

Thank
Mark

|||trim() doesn't works. It's doesn't remove the character!|||

hmm and if it's not a unicode character ?

Try putting this in a derived comlumn

REPLACE(TRIM(TXT)," ","")

the task will then complete with this in the output.

Warning: 0x80047034 at Data Flow Task, DTS.Pipeline: The DataFlow task has no components. Add components or remove the task.

|||

Use the REPLACE function, and the Unicode escape sequenece syntax Mark described.

It is a unicode character, as all comparisons are done as Unicode inside the SSIS expression parser, it cannot be anything else as far as SSIS is concerned. You need to find out what that is, and specify it in the REPLACE.

|||

Well but if the character > < is used in a replace within a dataflowtask in ssis, it automatic removes whatever flow you might have build inside that dataflow. In my opinion that seems like a bug..

if you want to do a replace in a sql task, you can't use a direct input (the sql task will then complete as if nothing was typed inside the task). You have to use a file connection for the query, so it seems like this character is the character from hell... :-)

So if you don't have the escape sequenece for this character (can't find it, since you can't search for it :-) ) you'll have to load the entire table to a temp table and do an ordinary replace in a sql query

|||

jam281 wrote:

it automatic removes whatever flow you might have build inside that dataflow.

Can you elaborate on exactly what you mean by "whatever flow you might have build".

-Jamie

|||Download any one of the many free hex editors on the Internet and open up a line of your source in it. Use the hex editor to find the hex value of the character in question. Go from there in your replace function.|||

"Can you elaborate on exactly what you mean by "whatever flow you might have build".

Allright. Try to create a new package - Add a dataflow and open it. Inside the dataflow create an oledb source - point to a table and map it.

Put in a derived column and a do a replace on one of the column like:

CENTRE == " " ? "Unknown" : CENTRE

put in a ole db destination - connect all tree

try to run it and it completes without doing anything. save the package and close the project.

Open the project again and your dataflow is now suddently empty.

The same problem apply if you have copied a sql query inside a sql task and it contains somewhere. The sql task will the execute witout doing anything...

|||

hmm found out that its a char(2) character.

select char(2)

gives that character. Now how do you replace char(2) in a derived column

|||

Let me know if using Unicode escape sequence as follows works for you:

CENTRE == "\x0002" ? "Unknown" : CENTRE

Thanks
Mark

|||

Mark Durley wrote:

Let me know if using Unicode escape sequence as follows works for you:

CENTRE == "\x0002" ? "Unknown" : CENTRE

Thanks
Mark

It worked thanks!!!

R

How do i replace that character in a derived column ?

Some rows have that character in one or more columns. If i just write this

column == "" ? Unknown : column

where the character is inside "" (can't write it here) the task will just succes without ever doing anything. The output says something like "the dataflow task had no tasks.....", which seems like a bug.

Use a conditional statement.

If [column] contains this value, replace it with another, else leave the value alone:

[column] == "A" ? "B" : [column]|||

i know but it's not a common character. Look at the Subject of this question!!!

It's a square character -> <-

It's a non XML valid character

|||

I think thats a new line character.

If you are using an OLEDB source for your data, you can just do a trim() on the column to get rid of it.

|||

If you know the Unicode character value for it, you can use an escape sequence:

"\xhhhh"

where hhhh is the Unicode character value.

Thank
Mark

|||trim() doesn't works. It's doesn't remove the character!|||

hmm and if it's not a unicode character ?

Try putting this in a derived comlumn

REPLACE(TRIM(TXT)," ","")

the task will then complete with this in the output.

Warning: 0x80047034 at Data Flow Task, DTS.Pipeline: The DataFlow task has no components. Add components or remove the task.

|||

Use the REPLACE function, and the Unicode escape sequenece syntax Mark described.

It is a unicode character, as all comparisons are done as Unicode inside the SSIS expression parser, it cannot be anything else as far as SSIS is concerned. You need to find out what that is, and specify it in the REPLACE.

|||

Well but if the character > < is used in a replace within a dataflowtask in ssis, it automatic removes whatever flow you might have build inside that dataflow. In my opinion that seems like a bug..

if you want to do a replace in a sql task, you can't use a direct input (the sql task will then complete as if nothing was typed inside the task). You have to use a file connection for the query, so it seems like this character is the character from hell... :-)

So if you don't have the escape sequenece for this character (can't find it, since you can't search for it :-) ) you'll have to load the entire table to a temp table and do an ordinary replace in a sql query

|||

jam281 wrote:

it automatic removes whatever flow you might have build inside that dataflow.

Can you elaborate on exactly what you mean by "whatever flow you might have build".

-Jamie

|||Download any one of the many free hex editors on the Internet and open up a line of your source in it. Use the hex editor to find the hex value of the character in question. Go from there in your replace function.|||

"Can you elaborate on exactly what you mean by "whatever flow you might have build".

Allright. Try to create a new package - Add a dataflow and open it. Inside the dataflow create an oledb source - point to a table and map it.

Put in a derived column and a do a replace on one of the column like:

CENTRE == " " ? "Unknown" : CENTRE

put in a ole db destination - connect all tree

try to run it and it completes without doing anything. save the package and close the project.

Open the project again and your dataflow is now suddently empty.

The same problem apply if you have copied a sql query inside a sql task and it contains somewhere. The sql task will the execute witout doing anything...

|||

hmm found out that its a char(2) character.

select char(2)

gives that character. Now how do you replace char(2) in a derived column

|||

Let me know if using Unicode escape sequence as follows works for you:

CENTRE == "\x0002" ? "Unknown" : CENTRE

Thanks
Mark

|||

Mark Durley wrote:

Let me know if using Unicode escape sequence as follows works for you:

CENTRE == "\x0002" ? "Unknown" : CENTRE

Thanks
Mark

It worked thanks!!!

Wednesday, March 7, 2012

Quick DISTINCT question

Hello all!
I know the following will work,
"SELECT DISTINCT Name, MIN(Sign) AS Sign
FROM Profile
GROUP BY Name"
Will return 2 columns, Name and Sign.
But what if I want more than just the two columns, and I need four to be
listed, but using the same code above. Just not sure how to add additional
columns without getting errors. Is this even possible?
TIA!!!
RudyIf you can show us some sample data and the required output we can come up
with some queries. Without that, you either add those additional columns to
the GROUP BY clause, or have then in the SELECT, within an aggregate
function.
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Rudy" <Rudy@.discussions.microsoft.com> wrote in message
news:5EC4A04B-AD95-40C6-BBEE-D8A1E9B3BF52@.microsoft.com...
Hello all!
I know the following will work,
"SELECT DISTINCT Name, MIN(Sign) AS Sign
FROM Profile
GROUP BY Name"
Will return 2 columns, Name and Sign.
But what if I want more than just the two columns, and I need four to be
listed, but using the same code above. Just not sure how to add additional
columns without getting errors. Is this even possible?
TIA!!!
Rudy|||Yes, you need to decide, for each of those other columns, which of the
possible multiple values that exists should be output by the query...
Since you are Grouping By Name, that means you will get one row in your
output per disntinct value of Name. There may be many rows in the original
Table for each value of Name, each with different values for these other
columns... So for each, you must tell query whether to output the Min(), the
Max(), the Sum(), AVG(), or whatever...
Select Name, MIN(Sign) AS Sign,
Min(Col1), Max(Col2), etc...
From Profile
Group By Name
If you want ALL the values of these other columns listed, as:
Name Col1 Col2
John 1 AA
John 2 AB
John 3 AC
etc.
then you can't group just by name, you need to add the other columns to the
group By clause
"Rudy" wrote:

> Hello all!
> I know the following will work,
> "SELECT DISTINCT Name, MIN(Sign) AS Sign
> FROM Profile
> GROUP BY Name"
> Will return 2 columns, Name and Sign.
> But what if I want more than just the two columns, and I need four to be
> listed, but using the same code above. Just not sure how to add additional
> columns without getting errors. Is this even possible?
> TIA!!!
> Rudy|||also, look at the with rollup and with group options for group, then you can
do stuff like:
Select Name, col1, min(Sign)
From Profile
Group By Name, col1 with rollup
and you will get all sorts of different levels...
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"CBretana" <cbretana@.areteIndNOSPAM.com> wrote in message
news:406DA4BA-6217-431D-B838-CA56B96C3453@.microsoft.com...
> Yes, you need to decide, for each of those other columns, which of the
> possible multiple values that exists should be output by the query...
> Since you are Grouping By Name, that means you will get one row in your
> output per disntinct value of Name. There may be many rows in the original
> Table for each value of Name, each with different values for these other
> columns... So for each, you must tell query whether to output the Min(),
> the
> Max(), the Sum(), AVG(), or whatever...
> Select Name, MIN(Sign) AS Sign,
> Min(Col1), Max(Col2), etc...
> From Profile
> Group By Name
> If you want ALL the values of these other columns listed, as:
> Name Col1 Col2
> John 1 AA
> John 2 AB
> John 3 AC
> etc.
> then you can't group just by name, you need to add the other columns to
> the
> group By clause
>
> "Rudy" wrote:
>|||Thanks you everyone for your suggestions! CBretana, your answer did the
trick. Thank!!!
Rudy
"CBretana" wrote:
> Yes, you need to decide, for each of those other columns, which of the
> possible multiple values that exists should be output by the query...
> Since you are Grouping By Name, that means you will get one row in your
> output per disntinct value of Name. There may be many rows in the original
> Table for each value of Name, each with different values for these other
> columns... So for each, you must tell query whether to output the Min(), t
he
> Max(), the Sum(), AVG(), or whatever...
> Select Name, MIN(Sign) AS Sign,
> Min(Col1), Max(Col2), etc...
> From Profile
> Group By Name
> If you want ALL the values of these other columns listed, as:
> Name Col1 Col2
> John 1 AA
> John 2 AB
> John 3 AC
> etc.
> then you can't group just by name, you need to add the other columns to th
e
> group By clause
>
> "Rudy" wrote:
>

Saturday, February 25, 2012

Quick and easy question, Sql update method . . .

I am new to Sql, so I think this is a really easy question.

But I am working on a 2005 MSSQL database.

When I add columns to an existing application with data and tables already being used, and the new column will be set to Database Null.

What is an easy way to quickly add the data to all the rows in the table.

For example if I am adding a checkbox, I've been doing it manually, add the column, change all the rows to False, one by one.

And then I can change it to Disallow DBNull.

As I get more and more users this could be a very time consuming process.

So the name of the Table is classifeds_Ads and let's say the column I want to add is Bonus and it needs to be filled with False.

How do I do this?

Thank you in advance

Daniel Meis

You can create a new query and then just run this:

UPDATE classifieds_Ads Set Bonus = 0

Or an easier approach is to use the Column Properties pane to set the initial properties for the column - Allow Nulls: No, Default Value or Binding: 0

|||

Works great, Thank you.