Showing posts with label contains. Show all posts
Showing posts with label contains. Show all posts

Wednesday, March 7, 2012

Fact Table SQL Query - adding a prefix to a value

Hi there, I have a question regarding a query to extract measures from a fact table. The fact table from the source system contains delivery notes with turnover in one dataset. The primary key is the delivery note number plus a consecutive number. The same table contains also the cancellations of the delivery note with the same turnover and the same primary key as the delivery note, only differed by another consecutive number. The cancellation is represented by another column which contains either a "0" or a "1" (cancellation no/yes).

The problem is that I'd like to change the turnover value for cancellations with a prefix instead of using another column in the fact table. Cause then I'd be able to group those numbers...

Is there a SQL function that allows me to

Example datasets:

Code Snippet

ConsNo DelNNo Canc Turnover Amount

001 200 0 1000 500

002 200 1 1000 500

I'd like to achieve this output by a query:

Code Snippet

ConsNo DelNNo Turnover Amount

001 200 1000 500

002 200 -1000 -500

Any ideas? I've heard of a function called "decode" but I think it doesn't work in SQL Server 2005...

Just create a view that depending on the Canc column multiplies the Turnover and Amount by 1 or -1.|||But how to use IF-statement and mathematical functions within a SELECT-statement? That would be T-SQL right?
|||

In SQL you can do something like:

select ConsNo,

DelNNo,

Turnover = case

when Canc = 0

then Turnover

else Turnover * -1

end,

Amount = case

when Canc = 0

then Amount

else Amount * -1

end

from <table name>

There is also the possibility to use isnull and nullif to simulate the previous cases.

|||

Tiago Rente wrote:

In SQL you can do something like:

select ConsNo,

DelNNo,

Turnover = case

when Canc = 0

then Turnover

else Turnover * -1

end,

Amount = case

when Canc = 0

then Amount

else Amount * -1

end

from <table name>

There is also the possibility to use isnull and nullif to simulate the previous cases.

It works, but when I add the GROUP BY function I always get an error message that "Canc" and "Turnover" aren't groupable!

Surprisingly I didn't even select the "Canc"-attribute, and I don't use Turnover within the GROUP-function.

|||

Unfortunately with this solution you have to copy the case statement to the group by section. In Sybase IQ you could use the name of the column in the group by without repeting the code.

In SQL Server the other option is to create a User Define Function that receives 2 columns (Canc, Turnover) or (Canc, Amount) and returns the correct value. This way you still need to copy the call to the UDF in the group by, but is less error prune. However, this will cost you in performance, since the UDF will be executed for each row in the table (as if you had open a cursor ).

Or you can create a view and then do the group by to the result of the view, this way you do not need to repeat the case or UDF in the group by since you already have a column name to do the group by.

|||

Tiago Rente wrote:

Unfortunately with this solution you have to copy the case statement to the group by section. In Sybase IQ you could use the name of the column in the group by without repeting the code.

In SQL Server the other option is to create a User Define Function that receives 2 columns (Canc, Turnover) or (Canc, Amount) and returns the correct value. This way you still need to copy the call to the UDF in the group by, but is less error prune. However, this will cost you in performance, since the UDF will be executed for each row in the table (as if you had open a cursor ).

Or you can create a view and then do the group by to the result of the view, this way you do not need to repeat the case or UDF in the group by since you already have a column name to do the group by.

I tried to use the case-statement in the GROUP BY function but the result is the same. Weird...

|||

Summing the case statements should do the trick.

Code Snippet

select ConsNo,

DelNNo,

Turnover = SUM(case

when Canc = 0

then Turnover

else Turnover * -1

end),

Amount = SUM(case

when Canc = 0

then Amount

else Amount * -1

end)

from <table name>

GROUP BY

ConsNo

, DelNo

facing problem to export crystal report to PDF which contains some items images

I am facing problem to export crystal report to PDF which contains some item's images.

All images change with first item image. the application developed in Visual Basic 6.0 and MS access.

The images comes to crystal report from physical location not from any database. While i m using default export utility of crystal report.See if you find solution here
support.BusinessObjects.com

Sunday, February 26, 2012

Extremely long lines of text

I have a dtsx package that works fine with one exception. When I open the dtsx package in BI, it gives me the following message:

Document contains one or more extremely long lines of text. These lines will cause the editor to respond slowly when you open the file. Do you still want to open the file?

When I respond yes, the package opens and I can edit or execute with no problem. Still, I want to understand what could cause this message to occur and, more importantly, how I can get rid of the message. When I try to simply execute the package I still get the same error and it seems this will be a problem for trying to run the package from SQL Server agent.

It seems likely to me that this message refers to the dtsx file (in xml format) itself. Does that make any sense?

This issue has been discussed in previous posts:

"Document contains one or more extremely long lines of text. These lines will cause the editor to respond slowly when you open the file. Do you still want to open the file?"

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=313598&SiteID=1

|||Thanks for the information. I obviously did not use the right terms when I searched.

Extremely long lines

Hi,

When i open a project in ssis show the message:

"Document contains one or more extremely long lines of text. These lines will cause the editor to respond slowly when you open the file. Do you still want to open the file."

I click Yes and my project open normally. Someone know why this happen? My project is small, have one package with any imports excel files to Sql Server 2005.

Thanks

Andr Rentes

Hi

Have a look at this link from the forum. Hope it helps:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=313598&SiteID=1

Cheers,

Grant

Friday, February 24, 2012

Extrating Data from One Database from Another

Hello,
I am new to sql (very new).
I have two database, let's call it database1 and database2.
Both database contains last name, first name and address information.
Database1 has approximatley 12000 records and database2 has approximately
2000 records. Here is what I am trying to accomplish. I will like to match
and extract data from database1 from database2 based on last name.
Thanks,
Steve,
select *
from database1.dbo.tbl t1
join database2.dbo.tbl t2
on t1,lastname = t2.lastname
"Steve" wrote:

> Hello,
> I am new to sql (very new).
> I have two database, let's call it database1 and database2.
> Both database contains last name, first name and address information.
> Database1 has approximatley 12000 records and database2 has approximately
> 2000 records. Here is what I am trying to accomplish. I will like to match
> and extract data from database1 from database2 based on last name.
> Thanks,
> Steve,

Extracting the duplicates using Fuzzy Grouping

Hi,

I have an Oracle table called "Party" which contains Party_Id as primary key and have Party_Name, Party_Addr etc., as fields. We have lot more duplicate party details such as (party_name and party_addr) in this table. We are trying to aviod duplicates using FUZZY logic of SSIS.

1. Is any body suggest me how to create package to avoid duplicates using Fuzzy logic for this scenario(Step by step instructions are good for me to understand SSIS).

2. Could you please provide me some samples for FUZZY(Please send me a sample to my email)

Ever heard of Google? http://www.google.ie/search?hl=en&q=ssis+fuzzy&meta=

Emailing defeats the object of having online forums and it is far easier for people to reply here than to send an email. Perhaps you could do the legwork yourself instead of asking people to do it for you?

-Jamie

Sunday, February 19, 2012

Extracting Last Name Only

I am fairly new to Crystal Reports and need some help extracting a last name from a field.
The field {{Byrname}} contains both first and last name as one text string. How do I extract just the last name?
Any help would be greatly appreciated.
Thanks,
Hanselright('David Tavin',instr('David Tavin',' ')-1)

before posting new thread do check out earlier threads
Thanks

Friday, February 17, 2012

Extracting data from each record in a column

I need to be pointed in the right direction on extracting data. I currently
have a clumn that contains a field that holds several different pieces of
data that I want to put into specific fields. Examples of the current data
in the Notes column is;
A&L-97-92 MOVED BY: Mr. Jenkins SECONDED BY: Mr. Holstock boundary changes
be received ****CARRIED.****
PW&P-181-92 MOVED BY: Mr. Gifford SECONDED BY: Mr. Moore scholarships be
awarded ****CARRIED.****
93-353 MOVED BY: Mr. Nelson SECONDED BY: Mr. Gifford ban the landfilling of
Old Corrugated Cardboard ****CARRIED.***
CW-20-01 MOVED BY: Mr. Cathcart SECONDED BY: Mr. Batten be received for
information. ****CARRIE
PW&P-144-96 MOVED BY: Mr. Mann SECONDED BY: Mr. Cathcart be received for
information. ****CARRIED.****
I would like to seperate this into the following fields;
MOTION MOVE SECOND COMMENTS
RESULT
-- -- --
-- --
A&L-97-92 Mr. Jenkins Mr. Holstock boundary changes be received
CARRIED.
PW&P-181-92 Mr. Gifford Mr. Moore scholarships be awarded
CARRIED.
93-353 Mr. Nelson Mr. Gifford ban the landfilling of Old
CARRIED.
Corrugated Cardboard
CW-20-01 Mr. Cathcart Mr. Batten be received for information.
CARRIED
PW&P-144-96 Mr. Mann Mr. Cathcart be received for information.
CARRIED.
Any help is appreciated.Assiming that all the columns are in the same table: test1,
Test1 (structure):
test
motion_result
move
second_by
comments
--
Assumptions:
Name in second_by column is always one word (Mr. xxx) - xxx as one word
There would always be 'MOVED BY:' and 'SECONDED BY:' strings in the source
update test1
set motion_result = ltrim(rtrim(substring(test, 1, (charindex('MOVED
BY',TEST) - 1) ))),
move = ltrim(rtrim(substring(test, (charindex('MOVED BY',TEST) + 9),
(charindex('SECONDED BY',TEST) - charindex('MOVED BY',TEST) -9 ) ))),
second_by = ltrim(rtrim(substring(test, (charindex('SECONDED BY',TEST) +
12), (charindex(' ', test, (charindex('SECONDED BY',TEST) + 17) ) -
charindex('SECONDED BY',TEST) - 12)))),
comments = replace(ltrim(rtrim(substring(test, charindex(' ', test
,charindex('SECONDED BY',TEST) + 18), 100))), '*','')
Check and modify according to your needs.....
T-Sql procedure would be easier, but could take time to run...
Hope it helps,
_Uday
"Christo" wrote:

> I need to be pointed in the right direction on extracting data. I current
ly
> have a clumn that contains a field that holds several different pieces of
> data that I want to put into specific fields. Examples of the current dat
a
> in the Notes column is;
> A&L-97-92 MOVED BY: Mr. Jenkins SECONDED BY: Mr. Holstock boundary changes
> be received ****CARRIED.****
> PW&P-181-92 MOVED BY: Mr. Gifford SECONDED BY: Mr. Moore scholarships be
> awarded ****CARRIED.****
> 93-353 MOVED BY: Mr. Nelson SECONDED BY: Mr. Gifford ban the landfilling o
f
> Old Corrugated Cardboard ****CARRIED.***
> CW-20-01 MOVED BY: Mr. Cathcart SECONDED BY: Mr. Batten be received for
> information. ****CARRIE
> PW&P-144-96 MOVED BY: Mr. Mann SECONDED BY: Mr. Cathcart be received for
> information. ****CARRIED.****
> I would like to seperate this into the following fields;
> MOTION MOVE SECOND COMMENTS
> RESULT
> -- -- --
> -- --
> A&L-97-92 Mr. Jenkins Mr. Holstock boundary changes be receiv
ed
> CARRIED.
> PW&P-181-92 Mr. Gifford Mr. Moore scholarships be awarded
> CARRIED.
> 93-353 Mr. Nelson Mr. Gifford ban the landfilling of Old
> CARRIED.
> Corrugated Cardboard
> CW-20-01 Mr. Cathcart Mr. Batten be received for informatio
n.
> CARRIED
> PW&P-144-96 Mr. Mann Mr. Cathcart be received for informatio
n.
> CARRIED.
> Any help is appreciated.|||Thanks for the help so far
I presummed all the records were complete but they are not, there are some
records that are missing Moved and Seconded, as well some missing seconded.
There are some records that are even blank. Is it simple enough to put in i
f
null statements? If so, where do I place them?
Thanks again for your help.
"Uday" wrote:
> Assiming that all the columns are in the same table: test1,
> --
> Test1 (structure):
> test
> motion_result
> move
> second_by
> comments
> --
> Assumptions:
> Name in second_by column is always one word (Mr. xxx) - xxx as one word
> There would always be 'MOVED BY:' and 'SECONDED BY:' strings in the source
> update test1
> set motion_result = ltrim(rtrim(substring(test, 1, (charindex('MOVED
> BY',TEST) - 1) ))),
> move = ltrim(rtrim(substring(test, (charindex('MOVED BY',TEST) + 9),
> (charindex('SECONDED BY',TEST) - charindex('MOVED BY',TEST) -9 ) ))),
> second_by = ltrim(rtrim(substring(test, (charindex('SECONDED BY',TEST) +
> 12), (charindex(' ', test, (charindex('SECONDED BY',TEST) + 17) ) -
> charindex('SECONDED BY',TEST) - 12)))),
> comments = replace(ltrim(rtrim(substring(test, charindex(' ', test
> ,charindex('SECONDED BY',TEST) + 18), 100))), '*','')
> Check and modify according to your needs.....
> T-Sql procedure would be easier, but could take time to run...
> Hope it helps,
> _Uday
> "Christo" wrote:
>|||Not sure If I understand your question correctly...
if you add where clause
where charindex('MOVED BY:', test) <> 0
and charindex('SECOND BY:', test) <> 0
to update just the good ones..
_Uday
"Christo" wrote:

> Thanks for the help so far
> I presummed all the records were complete but they are not, there are some
> records that are missing Moved and Seconded, as well some missing seconded
.
> There are some records that are even blank. Is it simple enough to put in
if
> null statements? If so, where do I place them?
> Thanks again for your help.
>|||I would basically want to put a 'null' value or blank data into the
corresponding new column if there was no data in the old column to pull.
"Uday" wrote:

> Not sure If I understand your question correctly...
> if you add where clause
> where charindex('MOVED BY:', test) <> 0
> and charindex('SECOND BY:', test) <> 0
> to update just the good ones..
> _Uday
> "Christo" wrote:
>
>|||On Thu, 8 Sep 2005 12:50:02 -0700, Christo wrote:

>I would basically want to put a 'null' value or blank data into the
>corresponding new column if there was no data in the old column to pull.
Hi Christo,
In that case, you'll have to use CASE in each of the assignments in the
SET clause, like this (for brevity, I won't repeat the complete string
manipulation expressions that were in a previous post in this thread)
UPDATE YourTable
SET motion_result = CASE
WHEN Notes LIKE '%MOVED BY%'
THEN -- complicated expression goes here
ELSE NULL
END,
move = CASE
WHEN Notes LIKE '%MOVED BY%SECONDED BY%'
THEN -- complicated expression goes here
ELSE NULL
END,
second_by = CASE
WHEN Notes LIKE '%SECONDED BY%'
THEN -- complicated expression goes here
ELSE NULL
END,
comments = CASE
WHEN Notes LIKE '%SECONDED BY%'
THEN -- complicated expression goes here
ELSE NULL
END
(untested - see www.aspfaq.com/5006 for the steps required to get tested
answers)
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)