Showing posts with label fields. Show all posts
Showing posts with label fields. Show all posts

Friday, March 30, 2012

How to from 1*apple,1*orange,1*apple to 2*apple,1*orange

Lets say there is a data table called ShoppingBasket. It has fields like "product", "price", "quantity" and "total" and so on. It is possible to have duplicates, but I think it is better to run a query and remove them. And update quantities. In the end, I plan to calculate total price.

For total price there seems to be a field or property "Formula" in column properties.

As this is really two questions, I take any help.

Leif


We need to see how your data looks like and also how you want it updated..

|||

"We need to see how your data looks like and also how you want it updated.." Here it comes.

I have a table called t_shopping_basket. There the user inserts items from products table "t_Tuote". I use this query:

"INSERT dbo.t_shopping_basket (Product_code, Name,Model,Quantity,Price,Alv) SELECT Tuotekoodi,Name,Model,Toimittajanimi,@.Quantity,Price,Alv FROM dbo.t_Tuote WHERE Product_code=@.Product_code", conn) ".

I have included also a gridView of "shopping basket" Its query is like:

"UPDATE [t_shopping_basket] SET [Product_code] = @.Product_code,[Quantity] = @.Quantity,[Name] = @.Name WHERE [Product_code] = @.Product_code"

Nothing prevents users pressing buy several times, so same item can be there in many places. If I leave them there, it has its good positive and negative sides. I probably should put an extra field like "item index" or so into the table then. Or I could leave quantity field out. 3 pieces means 3 rows of something.

Best way to my mind is to delete or prevent duplicates. But then, I have to find those duplicates first, and when I delete a record, I must increase item quantity. This feels like a complicated thing to do, especially with query.

How have others done this? What could my query look like?

Regards

Leif

how to format text fields

Hi all,
I´m just wondering, how to (RS2000):
How can I reach that a textfield content is being cut by a page break and
continued on page 2?
(In print preview mode: now if the textfield content doesn´t fit on the same
page, it´s printed on page 2, leaving a lot of blank space on page 1.
Let´s say the content is 30 lines long:
I simply want to get the first 20 lines on page 1 (till page end) and the
rest 10 lines on page 2.
I experimented, now CanGrow=True and CanShrink=True, but I didn´t find any
more properties controlling this behavior.)
Is there any way to format _parts_ of a textfield content in different ways
(f.e. some words bold)?
(Now each time a text shall be bold (f.e. headings and text) , I have to
create an own textbox and then an own textboxes for the text, followed by a
new sections and so on. That´s exhausting. Any better way to reach that?)
Thanks for tips!
Toni> How can I reach that a textfield content is being cut by a page break and
> continued on page 2?
> (In print preview mode: now if the textfield content doesn´t fit on the
> same page, it´s printed on page 2, leaving a lot of blank space on page 1.
Is the text field in a table or dumped to a textbox control?
-Tim
> Is there any way to format _parts_ of a textfield content in different
> ways (f.e. some words bold)?
There's no way I'm aware of that would allow this behavior. Font weight no
text boxes are pretty much an all or none property.
"Toni Pohl" <atwork43@.hotmail.com__nospam> wrote in message
news:OUwE$OreGHA.1204@.TK2MSFTNGP02.phx.gbl...
> Hi all,
> I´m just wondering, how to (RS2000):
> How can I reach that a textfield content is being cut by a page break and
> continued on page 2?
> (In print preview mode: now if the textfield content doesn´t fit on the
> same page, it´s printed on page 2, leaving a lot of blank space on page 1.
> Let´s say the content is 30 lines long:
> I simply want to get the first 20 lines on page 1 (till page end) and the
> rest 10 lines on page 2.
> I experimented, now CanGrow=True and CanShrink=True, but I didn´t find any
> more properties controlling this behavior.)
> Is there any way to format _parts_ of a textfield content in different
> ways (f.e. some words bold)?
> (Now each time a text shall be bold (f.e. headings and text) , I have to
> create an own textbox and then an own textboxes for the text, followed by
> a new sections and so on. That´s exhausting. Any better way to reach
> that?)
> Thanks for tips!
> Toni
>|||Hi Tim,
The field content is bound to a textbox control.
(The whole report contains mostly text in a lot of textboxes.)
Thanks,
Toni
"Tim Dot NoSpam" <Tim.NoSpam@.hughes.net> schrieb im Newsbeitrag
news:u8mnm6teGHA.4948@.TK2MSFTNGP04.phx.gbl...
>> How can I reach that a textfield content is being cut by a page break and
>> continued on page 2?
>> (In print preview mode: now if the textfield content doesn´t fit on the
>> same page, it´s printed on page 2, leaving a lot of blank space on page
>> 1.
> Is the text field in a table or dumped to a textbox control?
> -Tim
>> Is there any way to format _parts_ of a textfield content in different
>> ways (f.e. some words bold)?
> There's no way I'm aware of that would allow this behavior. Font weight
> no text boxes are pretty much an all or none property.
> "Toni Pohl" <atwork43@.hotmail.com__nospam> wrote in message
> news:OUwE$OreGHA.1204@.TK2MSFTNGP02.phx.gbl...
>> Hi all,
>> I´m just wondering, how to (RS2000):
>> How can I reach that a textfield content is being cut by a page break and
>> continued on page 2?
>> (In print preview mode: now if the textfield content doesn´t fit on the
>> same page, it´s printed on page 2, leaving a lot of blank space on page
>> 1.
>> Let´s say the content is 30 lines long:
>> I simply want to get the first 20 lines on page 1 (till page end) and the
>> rest 10 lines on page 2.
>> I experimented, now CanGrow=True and CanShrink=True, but I didn´t find
>> any more properties controlling this behavior.)
>> Is there any way to format _parts_ of a textfield content in different
>> ways (f.e. some words bold)?
>> (Now each time a text shall be bold (f.e. headings and text) , I have to
>> create an own textbox and then an own textboxes for the text, followed by
>> a new sections and so on. That´s exhausting. Any better way to reach
>> that?)
>> Thanks for tips!
>> Toni
>|||Toni:
Are your text boxes within a Table? If so, use a List object instead of
Tables. I've found this to work much better. There seems to be a bug in the
Table object when displaying large amounts of text.
HTH.
Richard.
"Toni Pohl" <atwork43@.hotmail.com__nospam> wrote in message
news:%23h763nxeGHA.4828@.TK2MSFTNGP05.phx.gbl...
> Hi Tim,
> The field content is bound to a textbox control.
> (The whole report contains mostly text in a lot of textboxes.)
> Thanks,
> Toni
> "Tim Dot NoSpam" <Tim.NoSpam@.hughes.net> schrieb im Newsbeitrag
> news:u8mnm6teGHA.4948@.TK2MSFTNGP04.phx.gbl...
>> How can I reach that a textfield content is being cut by a page break
>> and continued on page 2?
>> (In print preview mode: now if the textfield content doesn´t fit on the
>> same page, it´s printed on page 2, leaving a lot of blank space on page
>> 1.
>> Is the text field in a table or dumped to a textbox control?
>> -Tim
>> Is there any way to format _parts_ of a textfield content in different
>> ways (f.e. some words bold)?
>> There's no way I'm aware of that would allow this behavior. Font weight
>> no text boxes are pretty much an all or none property.
>> "Toni Pohl" <atwork43@.hotmail.com__nospam> wrote in message
>> news:OUwE$OreGHA.1204@.TK2MSFTNGP02.phx.gbl...
>> Hi all,
>> I´m just wondering, how to (RS2000):
>> How can I reach that a textfield content is being cut by a page break
>> and continued on page 2?
>> (In print preview mode: now if the textfield content doesn´t fit on the
>> same page, it´s printed on page 2, leaving a lot of blank space on page
>> 1.
>> Let´s say the content is 30 lines long:
>> I simply want to get the first 20 lines on page 1 (till page end) and
>> the rest 10 lines on page 2.
>> I experimented, now CanGrow=True and CanShrink=True, but I didn´t find
>> any more properties controlling this behavior.)
>> Is there any way to format _parts_ of a textfield content in different
>> ways (f.e. some words bold)?
>> (Now each time a text shall be bold (f.e. headings and text) , I have to
>> create an own textbox and then an own textboxes for the text, followed
>> by a new sections and so on. That´s exhausting. Any better way to reach
>> that?)
>> Thanks for tips!
>> Toni
>>
>|||I am haveing the exact same issue and my data is in a List object. Is
there anyone out there that has figured out a way to get the text to
flow spothly across pages?
Thanks
Edney Holder
Richard Wodabek wrote:
> Toni:
> Are your text boxes within a Table? If so, use a List object instead of
> Tables. I've found this to work much better. There seems to be a bug in t=he
> Table object when displaying large amounts of text.
> HTH.
> Richard.
> "Toni Pohl" <atwork43@.hotmail.com__nospam> wrote in message
> news:%23h763nxeGHA.4828@.TK2MSFTNGP05.phx.gbl...
> > Hi Tim,
> >
> > The field content is bound to a textbox control.
> > (The whole report contains mostly text in a lot of textboxes.)
> >
> > Thanks,
> > Toni
> >
> > "Tim Dot NoSpam" <Tim.NoSpam@.hughes.net> schrieb im Newsbeitrag
> > news:u8mnm6teGHA.4948@.TK2MSFTNGP04.phx.gbl...
> >> How can I reach that a textfield content is being cut by a page break
> >> and continued on page 2?
> >> (In print preview mode: now if the textfield content doesn=B4t fit on= the
> >> same page, it=B4s printed on page 2, leaving a lot of blank space on =page
> >> 1.
> >>
> >> Is the text field in a table or dumped to a textbox control?
> >>
> >> -Tim
> >>
> >> Is there any way to format _parts_ of a textfield content in different
> >> ways (f.e. some words bold)?
> >>
> >> There's no way I'm aware of that would allow this behavior. Font weig=ht
> >> no text boxes are pretty much an all or none property.
> >>
> >> "Toni Pohl" <atwork43@.hotmail.com__nospam> wrote in message
> >> news:OUwE$OreGHA.1204@.TK2MSFTNGP02.phx.gbl...
> >> Hi all,
> >>
> >> I=B4m just wondering, how to (RS2000):
> >>
> >> How can I reach that a textfield content is being cut by a page break
> >> and continued on page 2?
> >> (In print preview mode: now if the textfield content doesn=B4t fit on= the
> >> same page, it=B4s printed on page 2, leaving a lot of blank space on =page
> >> 1.
> >> Let=B4s say the content is 30 lines long:
> >> I simply want to get the first 20 lines on page 1 (till page end) and
> >> the rest 10 lines on page 2.
> >> I experimented, now CanGrow=3DTrue and CanShrink=3DTrue, but I didn==B4t find
> >> any more properties controlling this behavior.)
> >>
> >> Is there any way to format _parts_ of a textfield content in different
> >> ways (f.e. some words bold)?
> >> (Now each time a text shall be bold (f.e. headings and text) , I have= to
> >> create an own textbox and then an own textboxes for the text, followed
> >> by a new sections and so on. That=B4s exhausting. Any better way to r=each
> >> that?)
> >>
> >> Thanks for tips!
> >> Toni
> >>
> >>
> >>
> >
> >|||I am haveing the exact same issue and my data is in a List object. Is
there anyone out there that has figured out a way to get the text to
flow spothly across pages?
Thanks
Edney Holder
Richard Wodabek wrote:
> Toni:
> Are your text boxes within a Table? If so, use a List object instead of
> Tables. I've found this to work much better. There seems to be a bug in t=he
> Table object when displaying large amounts of text.
> HTH.
> Richard.
> "Toni Pohl" <atwork43@.hotmail.com__nospam> wrote in message
> news:%23h763nxeGHA.4828@.TK2MSFTNGP05.phx.gbl...
> > Hi Tim,
> >
> > The field content is bound to a textbox control.
> > (The whole report contains mostly text in a lot of textboxes.)
> >
> > Thanks,
> > Toni
> >
> > "Tim Dot NoSpam" <Tim.NoSpam@.hughes.net> schrieb im Newsbeitrag
> > news:u8mnm6teGHA.4948@.TK2MSFTNGP04.phx.gbl...
> >> How can I reach that a textfield content is being cut by a page break
> >> and continued on page 2?
> >> (In print preview mode: now if the textfield content doesn=B4t fit on= the
> >> same page, it=B4s printed on page 2, leaving a lot of blank space on =page
> >> 1.
> >>
> >> Is the text field in a table or dumped to a textbox control?
> >>
> >> -Tim
> >>
> >> Is there any way to format _parts_ of a textfield content in different
> >> ways (f.e. some words bold)?
> >>
> >> There's no way I'm aware of that would allow this behavior. Font weig=ht
> >> no text boxes are pretty much an all or none property.
> >>
> >> "Toni Pohl" <atwork43@.hotmail.com__nospam> wrote in message
> >> news:OUwE$OreGHA.1204@.TK2MSFTNGP02.phx.gbl...
> >> Hi all,
> >>
> >> I=B4m just wondering, how to (RS2000):
> >>
> >> How can I reach that a textfield content is being cut by a page break
> >> and continued on page 2?
> >> (In print preview mode: now if the textfield content doesn=B4t fit on= the
> >> same page, it=B4s printed on page 2, leaving a lot of blank space on =page
> >> 1.
> >> Let=B4s say the content is 30 lines long:
> >> I simply want to get the first 20 lines on page 1 (till page end) and
> >> the rest 10 lines on page 2.
> >> I experimented, now CanGrow=3DTrue and CanShrink=3DTrue, but I didn==B4t find
> >> any more properties controlling this behavior.)
> >>
> >> Is there any way to format _parts_ of a textfield content in different
> >> ways (f.e. some words bold)?
> >> (Now each time a text shall be bold (f.e. headings and text) , I have= to
> >> create an own textbox and then an own textboxes for the text, followed
> >> by a new sections and so on. That=B4s exhausting. Any better way to r=each
> >> that?)
> >>
> >> Thanks for tips!
> >> Toni
> >>
> >>
> >>
> >
> >sql

How to Format Text Area in Report

Hi,
I need create report that should look like a letter,
i.e. I have long, formatted text, where I should place few fields from
the record.
For instance:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dear Sir,
1. Hear goes
2. some formatted text
3. and {Fields!one_field.Value} inserted at line number 3
4. and {Fields!another_field.Value} inserted here
And text continues here
and here, and {Fields!next_filed.Value}
etc.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I did not found possibility to have one text box with formatted content
and fields/ calculations inserted into it in Report Design.
I tried also divide my text area to few text boxes where static text was
separated from data fields, but I've got into the issues with spacing
between the fields. It looks good in design view, but in preview it adds
extra vertical spaces within the fields. Also it is quite hard to format
a set of text boxes to look like one formatted letter.
Is it possible insert fields into formatted text box? If no, how in
general I should build such report?
Thanks for any help,
Alexander.On Dec 25, 2:38 am, "Alexander N. Treyner" <a...@.treyner.israel.net>
wrote:
> Hi,
> I need create report that should look like a letter,
> i.e. I have long, formatted text, where I should place few fields from
> the record.
> For instance:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Dear Sir,
> 1. Hear goes
> 2. some formatted text
> 3. and {Fields!one_field.Value} inserted at line number 3
> 4. and {Fields!another_field.Value} inserted here
> And text continues here
> and here, and {Fields!next_filed.Value}
> etc.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> I did not found possibility to have one text box with formatted content
> and fields/ calculations inserted into it in Report Design.
> I tried also divide my text area to few text boxes where static text was
> separated from data fields, but I've got into the issues with spacing
> between the fields. It looks good in design view, but in preview it adds
> extra vertical spaces within the fields. Also it is quite hard to format
> a set of text boxes to look like one formatted letter.
> Is it possible insert fields into formatted text box? If no, how in
> general I should build such report?
> Thanks for any help,
> Alexander.
You should consider using a table control in place of the textboxes.
This should allow for a little better layout/design flexibility. Also,
concatenating text and expressions/etc together as an expression is
fairly straight forward, i.e.,:
="and " + Fields!one_field.Value + "inserted at line number 3"
Hope this helps.
Regards,
Enrique Martinez
Sr. Software Consultant|||EMartinez wrote:
> You should consider using a table control in place of the textboxes.
> This should allow for a little better layout/design flexibility. Also,
> concatenating text and expressions/etc together as an expression is
> fairly straight forward, i.e.,:
> ="and " + Fields!one_field.Value + "inserted at line number 3"
> Hope this helps.
> Regards,
> Enrique Martinez
> Sr. Software Consultant
I tried to use expression, but it does not allow to format text. How can
I insert CRLF in the expression? I tried chr(10)+chr(13). It looks good
in preview, when I run report from my web site, seems it just ignore it
and print report without CRLF.
I will try to use tables.
Thanks,
Alex.|||EMartinez wrote:
> You should consider using a table control in place of the textboxes.
> This should allow for a little better layout/design flexibility. Also,
> concatenating text and expressions/etc together as an expression is
> fairly straight forward, i.e.,:
> ="and " + Fields!one_field.Value + "inserted at line number 3"
> Hope this helps.
> Regards,
> Enrique Martinez
> Sr. Software Consultant
I tried to use expression, but it does not allow to format text. How can
I insert CRLF in the expression? I tried chr(10)+chr(13). It looks good
in preview, when I run report from my web site, seems it just ignore it
and print report without CRLF.
I will try to use tables.
Thanks,
Alex.|||RS is pretty crummy at this time for this. RS 2008 will have much better
support for rich text. I have not experimented with it in pre-release
software so other than knowing the support will be better (i.e. there will
be support for rich text) I can't give you particulars.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Alexander N. Treyner" <alex@.treyner.israel.net> wrote in message
news:ufqbGGtRIHA.536@.TK2MSFTNGP06.phx.gbl...
> Hi,
> I need create report that should look like a letter,
> i.e. I have long, formatted text, where I should place few fields from the
> record.
> For instance:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Dear Sir,
> 1. Hear goes
> 2. some formatted text
> 3. and {Fields!one_field.Value} inserted at line number 3
> 4. and {Fields!another_field.Value} inserted here
> And text continues here
> and here, and {Fields!next_filed.Value}
> etc.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> I did not found possibility to have one text box with formatted content
> and fields/ calculations inserted into it in Report Design.
> I tried also divide my text area to few text boxes where static text was
> separated from data fields, but I've got into the issues with spacing
> between the fields. It looks good in design view, but in preview it adds
> extra vertical spaces within the fields. Also it is quite hard to format a
> set of text boxes to look like one formatted letter.
>
> Is it possible insert fields into formatted text box? If no, how in
> general I should build such report?
> Thanks for any help,
> Alexander.

Wednesday, March 21, 2012

How to find the first not used Char with a SELECT

I have a table Names with two fields:
ChID varchar(1)
Name varchar(25)
where the ChID char is in a range a .. z
(there will never be more then 27 records)
Some chars are used, some not
Two examples:
eg.
I have 4 records: CharID b, c, e, and f are used
I want to find the first not used char
In this example it is the char a
eg.
I have 5 records: CharID a, b, c, e, and f are used
I want to find the first not used char
In this example it is the char d.
Is a SELECT statement possible for finding the first not used Char?
How would such a statement be?Hi Henk,
Assuming all your ChID's are lower case, and a-z in ASCII:
CREATE TABLE NAMES(ChID varchar(1), Name varchar(25) NULL)
INSERT INTO Names(ChID) VALUES('f')
INSERT INTO Names(ChID) VALUES('b')
INSERT INTO Names(ChID) VALUES('c')
INSERT INTO Names(ChID) VALUES('e')
SELECT MIN(CHAR(ASCII(ChID) - 1)) FROM Names
WHERE NOT EXISTS(SELECT NULL FROM Names n2 WHERE ASCII(n2.ChID) =ASCII(Names.ChID)-1 )
AND ChID > 'a'
DROP TABLE Names
How do you get _27_ rows btw?
--
Jacco Schalkwijk MCDBA, MCSD, MCSE
Database Administrator
Eurostop Ltd.
"Henk Schreij" <henk@.schreijDOTnl> wrote in message
news:O$CUghtdDHA.1944@.TK2MSFTNGP12.phx.gbl...
> I have a table Names with two fields:
> ChID varchar(1)
> Name varchar(25)
> where the ChID char is in a range a .. z
> (there will never be more then 27 records)
> Some chars are used, some not
> Two examples:
> eg.
> I have 4 records: CharID b, c, e, and f are used
> I want to find the first not used char
> In this example it is the char a
> eg.
> I have 5 records: CharID a, b, c, e, and f are used
> I want to find the first not used char
> In this example it is the char d.
> Is a SELECT statement possible for finding the first not used Char?
> How would such a statement be?
>|||Jacco thanks,
It is a wonderful simple solution, exactly what I wanted.
You asked: How do you get _27_ rows btw?
Do you mean: How do you control that there will not be more then 27 rows?
The solution is that I use this SQL statement in a Delphi application. There
I use RecordCount, to limit the amount of records.
"Jacco Schalkwijk" <NOSPAMjaccos@.eurostop.co.uk> schreef in bericht
news:ur2NovtdDHA.1448@.TK2MSFTNGP12.phx.gbl...
> Hi Henk,
>
> Assuming all your ChID's are lower case, and a-z in ASCII:
> CREATE TABLE NAMES(ChID varchar(1), Name varchar(25) NULL)
> INSERT INTO Names(ChID) VALUES('f')
> INSERT INTO Names(ChID) VALUES('b')
> INSERT INTO Names(ChID) VALUES('c')
> INSERT INTO Names(ChID) VALUES('e')
> SELECT MIN(CHAR(ASCII(ChID) - 1)) FROM Names
> WHERE NOT EXISTS(SELECT NULL FROM Names n2 WHERE ASCII(n2.ChID) => ASCII(Names.ChID)-1 )
> AND ChID > 'a'
> DROP TABLE Names
> How do you get _27_ rows btw?
> --
> Jacco Schalkwijk MCDBA, MCSD, MCSE
> Database Administrator
> Eurostop Ltd.
>
> "Henk Schreij" <henk@.schreijDOTnl> wrote in message
> news:O$CUghtdDHA.1944@.TK2MSFTNGP12.phx.gbl...
> > I have a table Names with two fields:
> > ChID varchar(1)
> > Name varchar(25)
> > where the ChID char is in a range a .. z
> > (there will never be more then 27 records)
> > Some chars are used, some not
> >
> > Two examples:
> > eg.
> > I have 4 records: CharID b, c, e, and f are used
> > I want to find the first not used char
> > In this example it is the char a
> > eg.
> > I have 5 records: CharID a, b, c, e, and f are used
> > I want to find the first not used char
> > In this example it is the char d.
> >
> > Is a SELECT statement possible for finding the first not used Char?
> > How would such a statement be?
> >
> >
>|||the previous code won't work in case 'abc' (must be 'd') and in case of
empty table (must be 'a'). this one looks not so fine, but works
declare @.id varchar(1), @.fo varchar(1)
set @.fo='a'
declare MV cursor for select distinct lower(ChID) from Names where ChID
between 'a' and 'z' order by 1
Open MV
FETCH NEXT FROM MV INTO @.id
WHILE @.@.FETCH_STATUS = 0
BEGIN
if @.fo<>@.id BREAK
set @.fo=(CHAR(ASCII(@.fo) + 1))
FETCH NEXT FROM MV INTO @.id
END
CLOSE MV
DEALLOCATE MV
IF ASCII(@.fo)>122 set @.fo=NULL
print ISNULL(@.fo,'-')|||Hi Henk,
I meant that usually there are only 26 letters from a-z (well, definitly in
ASCII), so I was wondering where you got the 27th from?
--
Jacco Schalkwijk MCDBA, MCSD, MCSE
Database Administrator
Eurostop Ltd.
"Henk Schreij" <henk@.schreijDOTnl> wrote in message
news:%238Xc8$wdDHA.1944@.TK2MSFTNGP12.phx.gbl...
> Jacco thanks,
> It is a wonderful simple solution, exactly what I wanted.
> You asked: How do you get _27_ rows btw?
> Do you mean: How do you control that there will not be more then 27 rows?
> The solution is that I use this SQL statement in a Delphi application.
There
> I use RecordCount, to limit the amount of records.
> "Jacco Schalkwijk" <NOSPAMjaccos@.eurostop.co.uk> schreef in bericht
> news:ur2NovtdDHA.1448@.TK2MSFTNGP12.phx.gbl...
> > Hi Henk,
> >
> >
> > Assuming all your ChID's are lower case, and a-z in ASCII:
> >
> > CREATE TABLE NAMES(ChID varchar(1), Name varchar(25) NULL)
> >
> > INSERT INTO Names(ChID) VALUES('f')
> > INSERT INTO Names(ChID) VALUES('b')
> > INSERT INTO Names(ChID) VALUES('c')
> > INSERT INTO Names(ChID) VALUES('e')
> >
> > SELECT MIN(CHAR(ASCII(ChID) - 1)) FROM Names
> > WHERE NOT EXISTS(SELECT NULL FROM Names n2 WHERE ASCII(n2.ChID) => > ASCII(Names.ChID)-1 )
> > AND ChID > 'a'
> >
> > DROP TABLE Names
> >
> > How do you get _27_ rows btw?
> >
> > --
> > Jacco Schalkwijk MCDBA, MCSD, MCSE
> > Database Administrator
> > Eurostop Ltd.
> >
> >
> > "Henk Schreij" <henk@.schreijDOTnl> wrote in message
> > news:O$CUghtdDHA.1944@.TK2MSFTNGP12.phx.gbl...
> > > I have a table Names with two fields:
> > > ChID varchar(1)
> > > Name varchar(25)
> > > where the ChID char is in a range a .. z
> > > (there will never be more then 27 records)
> > > Some chars are used, some not
> > >
> > > Two examples:
> > > eg.
> > > I have 4 records: CharID b, c, e, and f are used
> > > I want to find the first not used char
> > > In this example it is the char a
> > > eg.
> > > I have 5 records: CharID a, b, c, e, and f are used
> > > I want to find the first not used char
> > > In this example it is the char d.
> > >
> > > Is a SELECT statement possible for finding the first not used Char?
> > > How would such a statement be?
> > >
> > >
> >
> >
>|||Sorry for the crosspost,
I also found out that the answer is not always correct.
(also thanks to news.rinet from russia)
I study this code to see if its better then the code I posted.
"Jacco Schalkwijk" <NOSPAMjaccos@.eurostop.co.uk> schreef in bericht
news:uyhXeT3dDHA.2816@.TK2MSFTNGP10.phx.gbl...
> Hi Henk,
> As pointed out in the other post it didn't work in all situations, but I
> have made the corrections in the code below.
> What the code now does is first check if there is a row that is 'a' (WHEN
> NOT EXISTS(SELECT NULL FROM Names n2 WHERE ChID = 'a') THEN 'a') , and if
> there isn't than that is of course the value you're looking for. This also
> catches the empty table. Next it will find the lowest ChID for which the
> next highest ChID in alphabetical order doesn't exists.
> You can also use a table variable with a-z in it and compare against that
> (second script)
> CREATE TABLE NAMES(ChID varchar(1), Name varchar(25) NULL)
> INSERT INTO Names(ChID) VALUES('a')
> INSERT INTO Names(ChID) VALUES('b')
> INSERT INTO Names(ChID) VALUES('c')
> INSERT INTO Names(ChID) VALUES('d')
> SELECT CASE WHEN NOT EXISTS(SELECT NULL FROM Names n2 WHERE ChID = 'a')
THEN
> 'a' ELSE
> MIN(CHAR(ASCII(ChID) + 1))
> END
> FROM Names
> WHERE
> NOT EXISTS(SELECT NULL FROM Names n2 WHERE ASCII(n2.ChID) => ASCII(Names.ChID)+1 )
> DROP TABLE Names
>
> CREATE TABLE NAMES(ChID varchar(1), Name varchar(25) NULL)
> INSERT INTO Names(ChID) VALUES('a')
> INSERT INTO Names(ChID) VALUES('b')
> INSERT INTO Names(ChID) VALUES('f')
> INSERT INTO Names(ChID) VALUES('d')
> DECLARE @.letters TABLE(letter char(1))
> DECLARE @.i TINYINT
> SET @.i = 97
> WHILE @.i < 123
> BEGIN
> INSERT INTO @.letters(letter) VALUES(CHAR(@.i))
> SET @.i = @.i +1
> END
> SELECT MIN(letter)
> FROM @.letters l
> LEFT OUTER JOIN Names n
> ON l.letter = n.ChID
> WHERE n.ChID IS NULL
>
> DROP TABLE Names
>
> --
> Jacco Schalkwijk MCDBA, MCSD, MCSE
> Database Administrator
> Eurostop Ltd.
>
> "Henk Schreij" <henk@.schreijDOTnl> wrote in message
> news:eIkC4dxdDHA.2168@.TK2MSFTNGP09.phx.gbl...
> > Jacco after studying your code, I must say it is not so simple as I
first
> > thought.
> > I do not understand the working of this piece of art yet, but I'am
trying.
> >
> > Oh, btw, a..z is 26 chars, not 27. I have to go to the primary school
> again
> > <g>.
> >
> > "Jacco Schalkwijk" <NOSPAMjaccos@.eurostop.co.uk> schreef in bericht
> > news:ur2NovtdDHA.1448@.TK2MSFTNGP12.phx.gbl...
> >
> > > SELECT MIN(CHAR(ASCII(ChID) - 1)) FROM Names
> > > WHERE NOT EXISTS(SELECT NULL FROM Names n2 WHERE ASCII(n2.ChID) => > > ASCII(Names.ChID)-1 )
> > > AND ChID > 'a'
> > >
> > > How do you get _27_ rows btw?
> > >
> > > "Henk Schreij" <henk@.schreijDOTnl> wrote in message
> > > news:O$CUghtdDHA.1944@.TK2MSFTNGP12.phx.gbl...
> > > > I have a table Names with two fields:
> > > > ChID varchar(1)
> > > > Name varchar(25)
> > > > where the ChID char is in a range a .. z
> > > > (there will never be more then 27 records)
> > > > Some chars are used, some not
> > > >
> > > > Two examples:
> > > > eg.
> > > > I have 4 records: CharID b, c, e, and f are used
> > > > I want to find the first not used char
> > > > In this example it is the char a
> > > > eg.
> > > > I have 5 records: CharID a, b, c, e, and f are used
> > > > I want to find the first not used char
> > > > In this example it is the char d.
> > > >
> > > > Is a SELECT statement possible for finding the first not used Char?
> > > > How would such a statement be?
> >
> >
> >
>|||I'am sorry that I have to tell you that the sql statement did'nt give the
correct answer.
Example:
CREATE TABLE NAMES(ChID varchar(1), Name varchar(25) NULL)
INSERT INTO Names(ChID) VALUES('f')
INSERT INTO Names(ChID) VALUES('a')
INSERT INTO Names(ChID) VALUES('b')
INSERT INTO Names(ChID) VALUES('c')
SELECT MIN(CHAR(ASCII(ChID) - 1)) FROM Names
WHERE NOT EXISTS(SELECT NULL FROM Names n2
WHERE ASCII(n2.ChID) = ASCII(Names.ChID)-1 )
AND ChID > 'a'
DROP TABLE Names
The result is an 'e' in stead of 'd' (the first free char)
But you showed me a way to handle this problem (thanks for that).
I made this statement:
CREATE TABLE Names (ChID varchar(1), Name varchar(25) NULL)
INSERT INTO Names(ChID) VALUES('c')
INSERT INTO Names(ChID) VALUES('b')
INSERT INTO Names(ChID) VALUES('a')
INSERT INTO Names(ChID) VALUES('z')
SELECT ISNULL(MIN(Nw), 'a') FROM (
SELECT CHAR(MIN(ASCII(ChID) + 1)) AS Nw
FROM Names WHERE NOT (ASCII(ChID) + 1) IN (SELECT ASCII(ChID) FROM Names)
UNION
SELECT (CASE WHEN (MIN(ChID) >= 'b') THEN 'a' END) AS Nw FROM Names) Tmp
DROP TABLE Names
It gives the correct answers (the ISNULL is for a empty table)
but the code is not very well designed, using a UNION.
Is it possible to get the same result without a union?
Henk.
> > > "Henk Schreij" <henk@.schreijDOTnl> wrote in message
> > > news:O$CUghtdDHA.1944@.TK2MSFTNGP12.phx.gbl...
> > > > I have a table Names with two fields:
> > > > ChID varchar(1)
> > > > Name varchar(25)
> > > > where the ChID char is in a range a .. z
> > > > (there will never be more then 27 records)
> > > > Some chars are used, some not
> > > >
> > > > Two examples:
> > > > eg.
> > > > I have 4 records: CharID b, c, e, and f are used
> > > > I want to find the first not used char
> > > > In this example it is the char a
> > > > eg.
> > > > I have 5 records: CharID a, b, c, e, and f are used
> > > > I want to find the first not used char
> > > > In this example it is the char d.
> > > >
> > > > Is a SELECT statement possible for finding the first not used Char?
> > > > How would such a statement be?|||Hi Henk,
The WHERE clause you have posted here
WHERE NOT (ASCII(ChID) + 1) IN (SELECT ASCII(ChID) FROM Names)
is logically equivalent to the WHERE clause in my post in the other part of
this thread
WHERE NOT EXISTS(SELECT NULL FROM Names n2 WHERE ASCII(n2.ChID) =ASCII(Names.ChID)+1)
I know that using IN is easier to understand than using EXISTS, but I advise
you to try to understand the use of EXISTS, because IN is limited to an
equality on one column, where with EXISTS you can use multiple columns and
different operators (<, >, BETWEEN, etc). On top of that EXISTS will always
perform as least as well as IN, and often it performs a lot better.
--
Jacco Schalkwijk MCDBA, MCSD, MCSE
Database Administrator
Eurostop Ltd.
"Henk Schreij" <henk@.schreijDOTnl> wrote in message
news:uDQfLY5dDHA.3584@.tk2msftngp13.phx.gbl...
> I made a syntesis of your and my statements:
> CREATE TABLE NAMES(ChID varchar(1), Name varchar(25) NULL)
> INSERT INTO Names(ChID) VALUES('d')
> INSERT INTO Names(ChID) VALUES('b')
> INSERT INTO Names(ChID) VALUES('c')
> INSERT INTO Names(ChID) VALUES('z')
> SELECT CASE
> WHEN NOT EXISTS (SELECT NULL FROM Names WHERE ChID = 'a') THEN 'a'
> ELSE CHAR(MIN(ASCII(ChID) + 1)) END
> FROM Names WHERE NOT (ASCII(ChID) + 1) IN (SELECT ASCII(ChID) FROM Names)
> I think this is the most elegant solution.
> Thanks a lot.
> Henk
> "Henk Schreij" <henk@.schreijDOTnl> schreef in bericht
> news:OPJslo4dDHA.3992@.TK2MSFTNGP11.phx.gbl...
> > I'am sorry that I have to tell you that the sql statement did'nt give
the
> > correct answer.
> >
> > Example:
> > CREATE TABLE NAMES(ChID varchar(1), Name varchar(25) NULL)
> > INSERT INTO Names(ChID) VALUES('f')
> > INSERT INTO Names(ChID) VALUES('a')
> > INSERT INTO Names(ChID) VALUES('b')
> > INSERT INTO Names(ChID) VALUES('c')
> >
> > SELECT MIN(CHAR(ASCII(ChID) - 1)) FROM Names
> > WHERE NOT EXISTS(SELECT NULL FROM Names n2
> > WHERE ASCII(n2.ChID) = ASCII(Names.ChID)-1 )
> > AND ChID > 'a'
> >
> > DROP TABLE Names
> >
> > The result is an 'e' in stead of 'd' (the first free char)
> >
> > But you showed me a way to handle this problem (thanks for that).
> >
> > I made this statement:
> > CREATE TABLE Names (ChID varchar(1), Name varchar(25) NULL)
> > INSERT INTO Names(ChID) VALUES('c')
> > INSERT INTO Names(ChID) VALUES('b')
> > INSERT INTO Names(ChID) VALUES('a')
> > INSERT INTO Names(ChID) VALUES('z')
> >
> > SELECT ISNULL(MIN(Nw), 'a') FROM (
> > SELECT CHAR(MIN(ASCII(ChID) + 1)) AS Nw
> > FROM Names WHERE NOT (ASCII(ChID) + 1) IN (SELECT ASCII(ChID) FROM
> Names)
> > UNION
> > SELECT (CASE WHEN (MIN(ChID) >= 'b') THEN 'a' END) AS Nw FROM Names)
Tmp
> >
> > DROP TABLE Names
> >
> > It gives the correct answers (the ISNULL is for a empty table)
> > but the code is not very well designed, using a UNION.
> >
> > Is it possible to get the same result without a union?
> >
> > Henk.
> > > > > "Henk Schreij" <henk@.schreijDOTnl> wrote in message
> > > > > news:O$CUghtdDHA.1944@.TK2MSFTNGP12.phx.gbl...
> > > > > > I have a table Names with two fields:
> > > > > > ChID varchar(1)
> > > > > > Name varchar(25)
> > > > > > where the ChID char is in a range a .. z
> > > > > > (there will never be more then 27 records)
> > > > > > Some chars are used, some not
> > > > > >
> > > > > > Two examples:
> > > > > > eg.
> > > > > > I have 4 records: CharID b, c, e, and f are used
> > > > > > I want to find the first not used char
> > > > > > In this example it is the char a
> > > > > > eg.
> > > > > > I have 5 records: CharID a, b, c, e, and f are used
> > > > > > I want to find the first not used char
> > > > > > In this example it is the char d.
> > > > > >
> > > > > > Is a SELECT statement possible for finding the first not used
> Char?
> > > > > > How would such a statement be?
>
>|||Jacco, thank you for this extra explanation.
I'll study the Exists in my SQL-book and try to use it more often, as it has
indeed some benefits over the IN statement.
"Jacco Schalkwijk" <NOSPAMjaccos@.eurostop.co.uk> schreef in bericht
news:#8QRez5dDHA.1460@.TK2MSFTNGP10.phx.gbl...
> Hi Henk,
> The WHERE clause you have posted here
> WHERE NOT (ASCII(ChID) + 1) IN (SELECT ASCII(ChID) FROM Names)
> is logically equivalent to the WHERE clause in my post in the other part
of
> this thread
> WHERE NOT EXISTS(SELECT NULL FROM Names n2 WHERE ASCII(n2.ChID) => ASCII(Names.ChID)+1)
> I know that using IN is easier to understand than using EXISTS, but I
advise
> you to try to understand the use of EXISTS, because IN is limited to an
> equality on one column, where with EXISTS you can use multiple columns and
> different operators (<, >, BETWEEN, etc). On top of that EXISTS will
always
> perform as least as well as IN, and often it performs a lot better.
> --
> Jacco Schalkwijk MCDBA, MCSD, MCSE
> Database Administrator
> Eurostop Ltd.
>
> "Henk Schreij" <henk@.schreijDOTnl> wrote in message
> news:uDQfLY5dDHA.3584@.tk2msftngp13.phx.gbl...
> > I made a syntesis of your and my statements:
> > CREATE TABLE NAMES(ChID varchar(1), Name varchar(25) NULL)
> > INSERT INTO Names(ChID) VALUES('d')
> > INSERT INTO Names(ChID) VALUES('b')
> > INSERT INTO Names(ChID) VALUES('c')
> > INSERT INTO Names(ChID) VALUES('z')
> >
> > SELECT CASE
> > WHEN NOT EXISTS (SELECT NULL FROM Names WHERE ChID = 'a') THEN 'a'
> > ELSE CHAR(MIN(ASCII(ChID) + 1)) END
> > FROM Names WHERE NOT (ASCII(ChID) + 1) IN (SELECT ASCII(ChID) FROM
Names)
> >
> > I think this is the most elegant solution.
> > Thanks a lot.
> > Henk
> >
> > "Henk Schreij" <henk@.schreijDOTnl> schreef in bericht
> > news:OPJslo4dDHA.3992@.TK2MSFTNGP11.phx.gbl...
> > > I'am sorry that I have to tell you that the sql statement did'nt give
> the
> > > correct answer.
> > >
> > > Example:
> > > CREATE TABLE NAMES(ChID varchar(1), Name varchar(25) NULL)
> > > INSERT INTO Names(ChID) VALUES('f')
> > > INSERT INTO Names(ChID) VALUES('a')
> > > INSERT INTO Names(ChID) VALUES('b')
> > > INSERT INTO Names(ChID) VALUES('c')
> > >
> > > SELECT MIN(CHAR(ASCII(ChID) - 1)) FROM Names
> > > WHERE NOT EXISTS(SELECT NULL FROM Names n2
> > > WHERE ASCII(n2.ChID) = ASCII(Names.ChID)-1 )
> > > AND ChID > 'a'
> > >
> > > DROP TABLE Names
> > >
> > > The result is an 'e' in stead of 'd' (the first free char)
> > >
> > > But you showed me a way to handle this problem (thanks for that).
> > >
> > > I made this statement:
> > > CREATE TABLE Names (ChID varchar(1), Name varchar(25) NULL)
> > > INSERT INTO Names(ChID) VALUES('c')
> > > INSERT INTO Names(ChID) VALUES('b')
> > > INSERT INTO Names(ChID) VALUES('a')
> > > INSERT INTO Names(ChID) VALUES('z')
> > >
> > > SELECT ISNULL(MIN(Nw), 'a') FROM (
> > > SELECT CHAR(MIN(ASCII(ChID) + 1)) AS Nw
> > > FROM Names WHERE NOT (ASCII(ChID) + 1) IN (SELECT ASCII(ChID) FROM
> > Names)
> > > UNION
> > > SELECT (CASE WHEN (MIN(ChID) >= 'b') THEN 'a' END) AS Nw FROM Names)
> Tmp
> > >
> > > DROP TABLE Names
> > >
> > > It gives the correct answers (the ISNULL is for a empty table)
> > > but the code is not very well designed, using a UNION.
> > >
> > > Is it possible to get the same result without a union?
> > >
> > > Henk.
> > > > > > "Henk Schreij" <henk@.schreijDOTnl> wrote in message
> > > > > > news:O$CUghtdDHA.1944@.TK2MSFTNGP12.phx.gbl...
> > > > > > > I have a table Names with two fields:
> > > > > > > ChID varchar(1)
> > > > > > > Name varchar(25)
> > > > > > > where the ChID char is in a range a .. z
> > > > > > > (there will never be more then 27 records)
> > > > > > > Some chars are used, some not
> > > > > > >
> > > > > > > Two examples:
> > > > > > > eg.
> > > > > > > I have 4 records: CharID b, c, e, and f are used
> > > > > > > I want to find the first not used char
> > > > > > > In this example it is the char a
> > > > > > > eg.
> > > > > > > I have 5 records: CharID a, b, c, e, and f are used
> > > > > > > I want to find the first not used char
> > > > > > > In this example it is the char d.
> > > > > > >
> > > > > > > Is a SELECT statement possible for finding the first not used
> > Char?
> > > > > > > How would such a statement be?
> >
> >
> >
>

Friday, March 9, 2012

how to find out column name with sql server store procedure

Hi
I have table which has Fields A,B,C and D for example. is thier any way to
retrive these field column as inline table function or store procedure.
thanks
some thing like select column_name from xxxx
thanksUSE pubs
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'autho
rs'
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"amjad" <amjad@.discussions.microsoft.com> wrote in message
news:B4AEB01C-6652-4681-AE71-6842385E4E17@.microsoft.com...
> Hi
> I have table which has Fields A,B,C and D for example. is thier any way to
> retrive these field column as inline table function or store procedure.
> thanks
> some thing like select column_name from xxxx
> thanks
>|||Or get it all in one variable with this technique:
USE pubs
GO
DECLARE @.fields VARCHAR(1000)
SELECT @.fields = ISNULL( @.fields, '' ) + column_name + ', '
FROM INFORMATION_SCHEMA.columns
WHERE table_name = 'authors'
-- Trim trailing space and comma
SET @.fields = SUBSTRING( @.fields, 1, LEN( @.fields) -1 )
SELECT @.fields
-- sp_columns gives some useful information too.
EXEC sp_columns 'authors'
"Tibor Karaszi" wrote:

> USE pubs
> SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'aut
hors'
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "amjad" <amjad@.discussions.microsoft.com> wrote in message
> news:B4AEB01C-6652-4681-AE71-6842385E4E17@.microsoft.com...
>
>

How to find nth lowest value in a row

Morning all,
I have a table with 500+ fields of numeric data (a time series of values) I
import from an external system. I need to find the 5th and 6th lowest values
in a given row to perform some calculations.
I currently do this by transposing the data row ie turning the row into a
column sorting it and then using row_num to get the 5th and 6th lowest
values. This transpose is a real bottleneck on my process.
Does anyone have any alternatives to my method ? All suggestions gratefully
received.
Thanks
WOn Thu, 16 Aug 2007 17:56:35 -0700, willcas wrote:
>Morning all,
>I have a table with 500+ fields of numeric data (a time series of values) I
>import from an external system. I need to find the 5th and 6th lowest values
>in a given row to perform some calculations.
>I currently do this by transposing the data row ie turning the row into a
>column sorting it and then using row_num to get the 5th and 6th lowest
>values. This transpose is a real bottleneck on my process.
>Does anyone have any alternatives to my method ? All suggestions gratefully
>received.
Hi W,
Perhaps you could transpose the data during the import and store it in a
more relational way?
The only other alternative would be a really very nasty (and long!) CASE
epxression that I won't even begin to think about <shudder>.
--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis|||"willcas" <willcas@.discussions.microsoft.com> wrote in message
news:6658592C-0F0A-45C6-BB9C-DFDDF0263FF2@.microsoft.com...
> Morning all,
> I have a table with 500+ fields of numeric data (a time series of values)
> I
> import from an external system. I need to find the 5th and 6th lowest
> values
> in a given row to perform some calculations.
> I currently do this by transposing the data row ie turning the row into a
> column sorting it and then using row_num to get the 5th and 6th lowest
> values. This transpose is a real bottleneck on my process.
> Does anyone have any alternatives to my method ? All suggestions
> gratefully
> received.
> Thanks
> W
I would treat this as a staging table and transform the data to a properly
normalized model. Then write your query against that new model.
Perhaps better still, do the transformation before the load (using
Integration Services for example).
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Can't you use unpivot for the transposition?
"willcas" <willcas@.discussions.microsoft.com> wrote in message
news:6658592C-0F0A-45C6-BB9C-DFDDF0263FF2@.microsoft.com...
> Morning all,
> I have a table with 500+ fields of numeric data (a time series of values)
> I
> import from an external system. I need to find the 5th and 6th lowest
> values
> in a given row to perform some calculations.
> I currently do this by transposing the data row ie turning the row into a
> column sorting it and then using row_num to get the 5th and 6th lowest
> values. This transpose is a real bottleneck on my process.
> Does anyone have any alternatives to my method ? All suggestions
> gratefully
> received.
> Thanks
> W

Friday, February 24, 2012

How to find duplicate rows in Flat File ?

In the FLAT FILE source, I have to find the duplicate rows based on the two fields say, "bill number" & "invoice date".

The rows within flat file has like "bill number" which is duplicated on the same "invoice date".

If duplicate rows found then move the duplicate rows into another Flat File.

If not found then move the rows into Sql Server Table.

Pls provide the solution. Thank you

Since, for duplicate records, the bill numbers would be the same as would the invoice dates, how do you chose which record to keep and which to move on to another flat file? Does it matter?|||

Example

BillNo, invoicedate, billamt, shiptype,

920203348313,08/12/07,1000,A

920203348313,08/12/07,1000,A

792309510000, 08/13/07,867,C

First two rows to be moved into another FLAT FILE

Third row to be moved into SQL SERVER table.

Thanks

|||

You could use a Rank() function to identify duplicates and to select which rows are going to be discarded/kept (you could load the files to an staging table).

If you were using a relational DB as source you do it like this. Jamie has also a Rank transformation that you may want to check. You could also write your own solution in a script component.,

|||

is there any direct solution by using any component within SSIS ?

|||

Antony Kumar wrote:

is there any direct solution by using any component within SSIS ?

A script component could do this pretty easily, provided you have the data sorted by the two keys and it would also likely require a two-pass approach. The first pass to number the rows, the second to move the rows where count (rownumber) > 1

|||

Antony Kumar wrote:

Example

BillNo, invoicedate, billamt, shiptype,

920203348313,08/12/07,1000,A

920203348313,08/12/07,1000,A

792309510000, 08/13/07,867,C

First two rows to be moved into another FLAT FILE

Third row to be moved into SQL SERVER table.

Thanks

Based on this example you could use an agregation transformation to count the rows group by BillNo; that should provide an extra column with the count. Then use a conditional split to filter out rows where count>1...

|||

Rafael Salas wrote:


Based on this example you could use an agregation transformation to count the rows group by BillNo; that should provide an extra column with the count. Then use a conditional split to filter out rows where count>1...

Oh sure! Go the easy route! Not sure what I was thinking earlier.

How to find duplicate records by tree field?

I have a table named student, there are tree fields GradeID, ClassID, Seat
in it.
How can I fild the duplicate record by the tree fields?
Perhaps this will help.
SELECT GradeID, ClassID, Seat, count(*) as Rows
FROM Students
GROUP BY GradeID, ClassID, Seat
HAVING count(*) > 1
Roy Harvey
Beacon Falls, CT
On Thu, 5 Oct 2006 05:45:22 +0800, "ad" <flying@.wfes.tcc.edu.tw>
wrote:

>I have a table named student, there are tree fields GradeID, ClassID, Seat
>in it.
>How can I fild the duplicate record by the tree fields?
>
|||try this
select Count(*),GradeID, ClassID, Seat
from dbo.tablename
group by GradeID, ClassID, Seat
having count(*) > 1
the count will show you how many rows are duplicated for each instance...
/*
Warren Brunk - MCITP - SQL 2005, MCDBA
www.techintsolutions.com
*/
"ad" <flying@.wfes.tcc.edu.tw> wrote in message
news:Ox9to5$5GHA.3292@.TK2MSFTNGP02.phx.gbl...
>I have a table named student, there are tree fields GradeID, ClassID, Seat
>in it.
> How can I fild the duplicate record by the tree fields?
>
|||Thanks,
The tabe's primary is PID, how can I show the duplicate rows with PID.

> select Count(*),GradeID, ClassID, Seat
> from dbo.tablename
> group by GradeID, ClassID, Seat
> having count(*) > 1
> the count will show you how many rows are duplicated for each instance...
> --
> /*
> Warren Brunk - MCITP - SQL 2005, MCDBA
> www.techintsolutions.com
> */
>
> "ad" <flying@.wfes.tcc.edu.tw> wrote in message
> news:Ox9to5$5GHA.3292@.TK2MSFTNGP02.phx.gbl...
>

How to find duplicate records by tree field?

I have a table named student, there are tree fields GradeID, ClassID, Seat
in it.
How can I fild the duplicate record by the tree fields?Perhaps this will help.
SELECT GradeID, ClassID, Seat, count(*) as Rows
FROM Students
GROUP BY GradeID, ClassID, Seat
HAVING count(*) > 1
Roy Harvey
Beacon Falls, CT
On Thu, 5 Oct 2006 05:45:22 +0800, "ad" <flying@.wfes.tcc.edu.tw>
wrote:

>I have a table named student, there are tree fields GradeID, ClassID, Seat
>in it.
>How can I fild the duplicate record by the tree fields?
>|||try this
select Count(*),GradeID, ClassID, Seat
from dbo.tablename
group by GradeID, ClassID, Seat
having count(*) > 1
the count will show you how many rows are duplicated for each instance...
--
/*
Warren Brunk - MCITP - SQL 2005, MCDBA
www.techintsolutions.com
*/
"ad" <flying@.wfes.tcc.edu.tw> wrote in message
news:Ox9to5$5GHA.3292@.TK2MSFTNGP02.phx.gbl...
>I have a table named student, there are tree fields GradeID, ClassID, Seat
>in it.
> How can I fild the duplicate record by the tree fields?
>|||Thanks,
The tabe's primary is PID, how can I show the duplicate rows with PID.

> select Count(*),GradeID, ClassID, Seat
> from dbo.tablename
> group by GradeID, ClassID, Seat
> having count(*) > 1
> the count will show you how many rows are duplicated for each instance...
> --
> /*
> Warren Brunk - MCITP - SQL 2005, MCDBA
> www.techintsolutions.com
> */
>
> "ad" <flying@.wfes.tcc.edu.tw> wrote in message
> news:Ox9to5$5GHA.3292@.TK2MSFTNGP02.phx.gbl...
>

How to find duplicate records by tree field?

I have a table named student, there are tree fields GradeID, ClassID, Seat
in it.
How can I fild the duplicate record by the tree fields?Perhaps this will help.
SELECT GradeID, ClassID, Seat, count(*) as Rows
FROM Students
GROUP BY GradeID, ClassID, Seat
HAVING count(*) > 1
Roy Harvey
Beacon Falls, CT
On Thu, 5 Oct 2006 05:45:22 +0800, "ad" <flying@.wfes.tcc.edu.tw>
wrote:
>I have a table named student, there are tree fields GradeID, ClassID, Seat
>in it.
>How can I fild the duplicate record by the tree fields?
>|||try this
select Count(*),GradeID, ClassID, Seat
from dbo.tablename
group by GradeID, ClassID, Seat
having count(*) > 1
the count will show you how many rows are duplicated for each instance...
--
/*
Warren Brunk - MCITP - SQL 2005, MCDBA
www.techintsolutions.com
*/
"ad" <flying@.wfes.tcc.edu.tw> wrote in message
news:Ox9to5$5GHA.3292@.TK2MSFTNGP02.phx.gbl...
>I have a table named student, there are tree fields GradeID, ClassID, Seat
>in it.
> How can I fild the duplicate record by the tree fields?
>|||Thanks,
The tabe's primary is PID, how can I show the duplicate rows with PID.
> select Count(*),GradeID, ClassID, Seat
> from dbo.tablename
> group by GradeID, ClassID, Seat
> having count(*) > 1
> the count will show you how many rows are duplicated for each instance...
> --
> /*
> Warren Brunk - MCITP - SQL 2005, MCDBA
> www.techintsolutions.com
> */
>
> "ad" <flying@.wfes.tcc.edu.tw> wrote in message
> news:Ox9to5$5GHA.3292@.TK2MSFTNGP02.phx.gbl...
>>I have a table named student, there are tree fields GradeID, ClassID, Seat
>>in it.
>> How can I fild the duplicate record by the tree fields?
>

how to find duplicate data involving more than one field

How can I query a database that checks for duplicate data in a combination
of fields. For instance, LastName may have many duplicates but I want to
find duplicates of LastName combined with FirstName. Thanks.SELECT firstname, lastname
FROM YourTable
GROUP BY firstname, lastname
HAVING COUNT(*)>1
David Portas
SQL Server MVP
--|||This is great to show what is duplicated and by adding changing Select to co
unt(*) I was able to see how many times it was duplicated. Are you able to t
ake this 1 step further and actually return all duplicated and complete reco
rds? EG. John,Smith is duplicated 3 times but the City is different in each
case. Can you return the 3 first,last,city records?
Robert Lassiter
quote:
Originally posted by David Portas
SELECT firstname, lastname
FROM YourTable
GROUP BY firstname, lastname
HAVING COUNT(*)>1
David Portas
SQL Server MVP
--

|||On Fri, 16 Dec 2005 12:16:57 -0600, rlassiter wrote:

>This is great to show what is duplicated and by adding changing Select
>to count(*) I was able to see how many times it was duplicated. Are you
>able to take this 1 step further and actually return all duplicated and
>complete records? EG. John,Smith is duplicated 3 times but the City is
>different in each case. Can you return the 3 first,last,city records?
>Robert Lassiter
Hi Robert,
Here's one method:
SELECT a.firstname, a.lastname, a.city
FROM YourTable AS a
WHERE (SELECT COUNT(*)
FROM YourTable AS b
WHERE b.firstname = a.firstname
AND b.lastname = a.lastname) > 1
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Sunday, February 19, 2012

How to filter out unwanted data


I have the following fields in table A:
Date | Descrip | Amt Dr
--
01/02/2006 | 740240 |(2,400.00)
14/02/2006 | 740241 |(3,000.00)
15/02/2006 | 41142 | 1,800.00
20/02/2006 | 41142 | 2,700.00
25/02/2006 | 740245 | 5,200.00
I have the following fields in table B:
Date | Descrip | Amt Dr
--
02/02/2006 |88258 | 1,400.00
17/02/2006 |740244 | (1,500.00)
25/02/2006 |740245 | 5,200.00
There are no referencial key between TableA & TableB,
What i want is to extract the date,descrip & Amt data from
Table A where it's Descrip data is not the same as the data
in Table B's Descrip column.
My sql syntax is as follows:
SELECT
CASE WHEN TableA.Amt < 0 THEN TableA.[Date] ELSE 0 END,
CASE WHEN TableA.Amt < 0 THEN TableA.Descrip ELSE 0 END,
CASE WHEN TableA.Amt < 0 THEN TableA.Amt - (TableA.Amt * 2)ELSE 0 END AS
[Add Back]
FROM TableA,TableB
WHERE TableA.Descrip <> TableB.Descrip
GROUP BY TableA.Date,TableA.Amt,TableA.Descrip
The output of the above is as follows:
Date | Descrip | Amt Dr
--
01/02/2006 | 740240 |(2,400.00)
14/02/2006 | 740241 |(3,000.00)
15/02/2006 | 0 | 0
20/02/2006 | 0 | 0
25/02/2006 | 740245 | 5,200.00
Notice that, descrip with 740245 appearing in both tables
is what the sql should filter out, but failed to do so,
what i want is as below:
Date | Descrip | Amt Dr
--
01/02/2006 | 740240 |(2,400.00)
14/02/2006 | 740241 |(3,000.00)
Can i achieve this? Please help.
*** Sent via Developersdex http://www.examnotes.net ***Dave
Untested
SELECT * FROM TableA WHERE NOT EXISTS
(SELECT * FROM TableB WHERE TableA.Descr<>Table.Descr)
"Dave dcartford" <dcartford@.gmail.com> wrote in message
news:ucygLFEaGHA.1192@.TK2MSFTNGP04.phx.gbl...
>
> I have the following fields in table A:
> Date | Descrip | Amt Dr
> --
> 01/02/2006 | 740240 |(2,400.00)
> 14/02/2006 | 740241 |(3,000.00)
> 15/02/2006 | 41142 | 1,800.00
> 20/02/2006 | 41142 | 2,700.00
> 25/02/2006 | 740245 | 5,200.00
> I have the following fields in table B:
> Date | Descrip | Amt Dr
> --
> 02/02/2006 |88258 | 1,400.00
> 17/02/2006 |740244 | (1,500.00)
> 25/02/2006 |740245 | 5,200.00
> There are no referencial key between TableA & TableB,
> What i want is to extract the date,descrip & Amt data from
> Table A where it's Descrip data is not the same as the data
> in Table B's Descrip column.
> My sql syntax is as follows:
>
> SELECT
> CASE WHEN TableA.Amt < 0 THEN TableA.[Date] ELSE 0 END,
> CASE WHEN TableA.Amt < 0 THEN TableA.Descrip ELSE 0 END,
> CASE WHEN TableA.Amt < 0 THEN TableA.Amt - (TableA.Amt * 2)ELSE 0 END AS
> [Add Back]
> FROM TableA,TableB
> WHERE TableA.Descrip <> TableB.Descrip
> GROUP BY TableA.Date,TableA.Amt,TableA.Descrip
> The output of the above is as follows:
> Date | Descrip | Amt Dr
> --
> 01/02/2006 | 740240 |(2,400.00)
> 14/02/2006 | 740241 |(3,000.00)
> 15/02/2006 | 0 | 0
> 20/02/2006 | 0 | 0
> 25/02/2006 | 740245 | 5,200.00
> Notice that, descrip with 740245 appearing in both tables
> is what the sql should filter out, but failed to do so,
> what i want is as below:
>
> Date | Descrip | Amt Dr
> --
> 01/02/2006 | 740240 |(2,400.00)
> 14/02/2006 | 740241 |(3,000.00)
>
> Can i achieve this? Please help.
>
>
> *** Sent via Developersdex http://www.examnotes.net ***|||Is someone else posting from Uri's name.. juz joking :)
try this
SELECT * FROM TableA WHERE NOT EXISTS
(SELECT * FROM TableB WHERE TableA.Descr=Table.Descr)
"Uri Dimant" wrote:

> Dave
> Untested
> SELECT * FROM TableA WHERE NOT EXISTS
> (SELECT * FROM TableB WHERE TableA.Descr<>Table.Descr)
>
> "Dave dcartford" <dcartford@.gmail.com> wrote in message
> news:ucygLFEaGHA.1192@.TK2MSFTNGP04.phx.gbl...
>
>|||>> > Table A where it's Descrip data is not the same as the data
Just change NOT EXISTS to EXISTS
create table #table_a (c1 datetime,descr varchar(10))
create table #table_b (c1 datetime,descr varchar(10))
insert #table_a values ('20060101','a')
insert #table_a values ('20060101','h')
insert #table_a values ('20060101','r')
insert #table_b values ('20060101','a')
insert #table_b values ('20060101','c')
select * from #table_a where exists
(select * from #table_b where #table_a.descr=#table_b.descr)
drop table #table_a,#table_b
"Omnibuzz" <Omnibuzz@.discussions.microsoft.com> wrote in message
news:3F740FCC-A686-49F9-BF5C-7544C822E32D@.microsoft.com...
> Is someone else posting from Uri's name.. juz joking :)
> try this
> SELECT * FROM TableA WHERE NOT EXISTS
> (SELECT * FROM TableB WHERE TableA.Descr=Table.Descr)
> "Uri Dimant" wrote:
>|||Uri,
Shouldn't the query be like this' I apologise if I irritated you.
select * from #table_a where not exists
(select * from #table_b where #table_a.descr=#table_b.descr)|||Hi
Doh, I need a cofee , my mistake. I don't why ,i have been assumed that he
needs the same descr to get out
"Omnibuzz" <Omnibuzz@.discussions.microsoft.com> wrote in message
news:6A886FB3-F225-4863-A453-C0E6C07F1819@.microsoft.com...
> Uri,
> Shouldn't the query be like this' I apologise if I irritated you.
> select * from #table_a where not exists
> (select * from #table_b where #table_a.descr=#table_b.descr)
>