Showing posts with label rows. Show all posts
Showing posts with label rows. Show all posts

Thursday, March 29, 2012

Edit connection manager connection string at runtime with c#

This is the first time I have used SSIS, so please bear with the ignorance.

I have a super simple package that inserts x000's of rows into a temporary table. The data source is a file that the user will upload. I need to be able to tell the package what file to upload. I'm thinking the simplest thing would be to edit the connectionString property of the SourceConnectionFlatFile at runtime. Is this possible? What form should the file path be in (UNC, other)? And, are there any other considerations I should be aware of?

Thanks!

Package configurations were designed for just this purpose.

Easy way to remove international alphabet from all rows?

Is there an easy way to loop through all rows and remove all
international alphabet characters from a column in a table, for example
remove German umlauts "" and convert them to a simple "u".
Thanks,
lqSee the following thread:
http://groups-beta.google.com/group...b45abaa5cf410b8

Razvan|||OK< thanks on that. How about keeping out these characters in the first
place?|||laurenq uantrell (laurenquantrell@.hotmail.com) writes:
> Is there an easy way to loop through all rows and remove all
> international alphabet characters from a column in a table, for example
> remove German umlauts "" and convert them to a simple "u".

Here is a much smarter version than the one in the linkn Razvan foun

create table T (
s nvarchar(20)
)
insert into T values ('cre')
insert into T values ('pt de fois gras')
insert into T values ('HLNE MELANON')

update T
set s = convert(varchar(20), s) COLLATE Cyrillic_General_CS_AS
go
select * from T
go
drop table T

This assumes that your data only has Latin characters.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||laurenq uantrell (laurenquantrell@.hotmail.com) writes:
> OK< thanks on that. How about keeping out these characters in the first
> place?

I don't know, nuke the parts of the world where we insist on using other
languages than English?

Seriously, I think it would be a very bad idea. If you want to send
mail to these persons, you do want to spell their names properly, don't
you?

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||That's only one of the problems! I want to store the data with the
international characters but then I need to strip out the international
characters for certain output, such as in e-mail addresses...
lq|||Technically, international characters are permitted in email addresses
and domain names so stripping them out is still a bad idea.

You'll have to build your own table to translate characters that you
deem to be unacceptable. Google for some conversion tables but there
isn't really a single answer because it depends on which characters you
need to support (don't forget the two-byte character sets used in the
Far East and elsewhere for example).

--
David Portas
SQL Server MVP
--|||laurenq uantrell (laurenquantrell@.hotmail.com) writes:
> That's only one of the problems! I want to store the data with the
> international characters but then I need to strip out the international
> characters for certain output, such as in e-mail addresses...

I would recomment that you store the e-mail address. While the e-mail
address often can be formed as firstname.lastname@.domain.xxx, this is
not a requirement.

And the local transformation may not be the one you expect. in German
after often replaced with ae, oe and ue. (Whether this is actually common
in mail addresses, I don't know.)

If you are thinking of the comment part of the e-mail address:

John Smith <johnsmith@.example.com
(John Smith is the comment here) You should either encode the comment
according to MIME as per RFC2047, or send as-is. But don't misspell
people's names.

(By the way, permit me to point out that the term "international characters"
is a misnomer. The internationalest characters I can think of is the
English alphabet A-Z. Non-ASCII characters is a better term, and
technically precise.)

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Erland,
Thanks for that. You're right, I do mean non-ASCII characters...
This gets tricky because many city names and people names contain
non-ASCII characters and I want to display then properly, however, some
systems do not support non-ASCII characters and they need to be
cleansed for output to those systems, so as you point out, there is not
an always correct translation into ASCII characters.|||laurenq uantrell (laurenquantrell@.hotmail.com) writes:
> Thanks for that. You're right, I do mean non-ASCII characters...
> This gets tricky because many city names and people names contain
> non-ASCII characters and I want to display then properly, however, some
> systems do not support non-ASCII characters and they need to be
> cleansed for output to those systems, so as you point out, there is not
> an always correct translation into ASCII characters.

Systems in 2005 that is not capable to handle non-ASCII characters? So,
not all programs are capable to handle Unicode, but one would at least
imagine that they should be able handle 8-bit charset. If I were you,
I would consider to attempt to kill these systems by starvation and
not feed them any data. :-)

On a more serious point, there are one letter that the snippet I
posted does not handle and that is . This gets converted into a ?.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Windows file names is an example on one such system...|||Which Windows are you referring to? FAT32? NTFS does support non-ASCII
characters in files names, at least it does under Win 2003 so I don't
know why it wouldn't under other versions.

--
David Portas
SQL Server MVP
--|||laurenq uantrell (laurenquantrell@.hotmail.com) writes:
> Windows file names is an example on one such system...

The 8.3 names, yes, but you rarely have to see them. Even less rarely
have to form them. As long as you are on NTFS you can use the whole range
of Unicode, and use letters from any script. The FAT files systems may
not support this, but I'm pretty sure that they support the full range
of the current ANSI code page.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.aspsql

Tuesday, March 27, 2012

Easy way to find size of data returned in SQL 2005 ?

Id like to know when i have a query that returns say 12 million rows as an
example, is there an easy way to find out how much of data that is in MB or
GB ?
Thanks
Hassan
There's no automatic way. You could estimate the size of each row, and then
multiply by @.@.rowcount. Or capture the data in a temp table and use
sp_spaceused. Or find a tool that measures how much data is sent over the
network. There is a client statistics option in Query Analyzer and SSMS, but
I can't imagine you really want to send all 12 million rows to the client.
You've been asking lots of questions lately, and lots of people have been
providing answers. It would be nice to know if the answers you are getting
are useful to you.
HTH
Kalen Delaney, SQL Server MVP
http://sqlblog.com
"Hassan" <Hassan@.hotmail.com> wrote in message
news:OhXtCTDGHHA.2464@.TK2MSFTNGP06.phx.gbl...
> Id like to know when i have a query that returns say 12 million rows as an
> example, is there an easy way to find out how much of data that is in MB
> or GB ?
> Thanks
>
|||Hello,
My suggestion will be:-
Populate a sample of 2 million row into a temp table and then use
SP_SPaceused. After that you could take an average of size per record and
multiply by total returned. There
is no direct method to know this...
Thanks
Hari
"Hassan" <Hassan@.hotmail.com> wrote in message
news:OhXtCTDGHHA.2464@.TK2MSFTNGP06.phx.gbl...
> Id like to know when i have a query that returns say 12 million rows as an
> example, is there an easy way to find out how much of data that is in MB
> or GB ?
> Thanks
>
|||Kalen,
I know at times it may appear that I am very thankless, but if not for the
newsgroup and the responses I get that have been very positive and
satisfactory, I wouldnt have been posting time and again out here.
Id love to thank all of the users for responding to not just my questions
but to others questions as well.
Keep up the good work..
"Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
news:O0mQbYDGHHA.5104@.TK2MSFTNGP03.phx.gbl...
> Hassan
> There's no automatic way. You could estimate the size of each row, and
> then multiply by @.@.rowcount. Or capture the data in a temp table and use
> sp_spaceused. Or find a tool that measures how much data is sent over the
> network. There is a client statistics option in Query Analyzer and SSMS,
> but I can't imagine you really want to send all 12 million rows to the
> client.
> You've been asking lots of questions lately, and lots of people have been
> providing answers. It would be nice to know if the answers you are getting
> are useful to you.
> --
> HTH
> Kalen Delaney, SQL Server MVP
> http://sqlblog.com
>
> "Hassan" <Hassan@.hotmail.com> wrote in message
> news:OhXtCTDGHHA.2464@.TK2MSFTNGP06.phx.gbl...
>

Easy way to find size of data returned in SQL 2005 ?

Id like to know when i have a query that returns say 12 million rows as an
example, is there an easy way to find out how much of data that is in MB or
GB ?
ThanksHassan
There's no automatic way. You could estimate the size of each row, and then
multiply by @.@.rowcount. Or capture the data in a temp table and use
sp_spaceused. Or find a tool that measures how much data is sent over the
network. There is a client statistics option in Query Analyzer and SSMS, but
I can't imagine you really want to send all 12 million rows to the client.
You've been asking lots of questions lately, and lots of people have been
providing answers. It would be nice to know if the answers you are getting
are useful to you.
--
HTH
Kalen Delaney, SQL Server MVP
http://sqlblog.com
"Hassan" <Hassan@.hotmail.com> wrote in message
news:OhXtCTDGHHA.2464@.TK2MSFTNGP06.phx.gbl...
> Id like to know when i have a query that returns say 12 million rows as an
> example, is there an easy way to find out how much of data that is in MB
> or GB ?
> Thanks
>|||Hello,
My suggestion will be:-
Populate a sample of 2 million row into a temp table and then use
SP_SPaceused. After that you could take an average of size per record and
multiply by total returned. There
is no direct method to know this...
Thanks
Hari
"Hassan" <Hassan@.hotmail.com> wrote in message
news:OhXtCTDGHHA.2464@.TK2MSFTNGP06.phx.gbl...
> Id like to know when i have a query that returns say 12 million rows as an
> example, is there an easy way to find out how much of data that is in MB
> or GB ?
> Thanks
>|||Kalen,
I know at times it may appear that I am very thankless, but if not for the
newsgroup and the responses I get that have been very positive and
satisfactory, I wouldnt have been posting time and again out here.
Id love to thank all of the users for responding to not just my questions
but to others questions as well.
Keep up the good work..
"Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
news:O0mQbYDGHHA.5104@.TK2MSFTNGP03.phx.gbl...
> Hassan
> There's no automatic way. You could estimate the size of each row, and
> then multiply by @.@.rowcount. Or capture the data in a temp table and use
> sp_spaceused. Or find a tool that measures how much data is sent over the
> network. There is a client statistics option in Query Analyzer and SSMS,
> but I can't imagine you really want to send all 12 million rows to the
> client.
> You've been asking lots of questions lately, and lots of people have been
> providing answers. It would be nice to know if the answers you are getting
> are useful to you.
> --
> HTH
> Kalen Delaney, SQL Server MVP
> http://sqlblog.com
>
> "Hassan" <Hassan@.hotmail.com> wrote in message
> news:OhXtCTDGHHA.2464@.TK2MSFTNGP06.phx.gbl...
>

Easy way to find size of data returned in SQL 2005 ?

Id like to know when i have a query that returns say 12 million rows as an
example, is there an easy way to find out how much of data that is in MB or
GB ?
ThanksHassan
There's no automatic way. You could estimate the size of each row, and then
multiply by @.@.rowcount. Or capture the data in a temp table and use
sp_spaceused. Or find a tool that measures how much data is sent over the
network. There is a client statistics option in Query Analyzer and SSMS, but
I can't imagine you really want to send all 12 million rows to the client.
You've been asking lots of questions lately, and lots of people have been
providing answers. It would be nice to know if the answers you are getting
are useful to you.
--
HTH
Kalen Delaney, SQL Server MVP
http://sqlblog.com
"Hassan" <Hassan@.hotmail.com> wrote in message
news:OhXtCTDGHHA.2464@.TK2MSFTNGP06.phx.gbl...
> Id like to know when i have a query that returns say 12 million rows as an
> example, is there an easy way to find out how much of data that is in MB
> or GB ?
> Thanks
>|||Hello,
My suggestion will be:-
Populate a sample of 2 million row into a temp table and then use
SP_SPaceused. After that you could take an average of size per record and
multiply by total returned. There
is no direct method to know this...
Thanks
Hari
"Hassan" <Hassan@.hotmail.com> wrote in message
news:OhXtCTDGHHA.2464@.TK2MSFTNGP06.phx.gbl...
> Id like to know when i have a query that returns say 12 million rows as an
> example, is there an easy way to find out how much of data that is in MB
> or GB ?
> Thanks
>|||Kalen,
I know at times it may appear that I am very thankless, but if not for the
newsgroup and the responses I get that have been very positive and
satisfactory, I wouldnt have been posting time and again out here.
Id love to thank all of the users for responding to not just my questions
but to others questions as well.
Keep up the good work..
"Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
news:O0mQbYDGHHA.5104@.TK2MSFTNGP03.phx.gbl...
> Hassan
> There's no automatic way. You could estimate the size of each row, and
> then multiply by @.@.rowcount. Or capture the data in a temp table and use
> sp_spaceused. Or find a tool that measures how much data is sent over the
> network. There is a client statistics option in Query Analyzer and SSMS,
> but I can't imagine you really want to send all 12 million rows to the
> client.
> You've been asking lots of questions lately, and lots of people have been
> providing answers. It would be nice to know if the answers you are getting
> are useful to you.
> --
> HTH
> Kalen Delaney, SQL Server MVP
> http://sqlblog.com
>
> "Hassan" <Hassan@.hotmail.com> wrote in message
> news:OhXtCTDGHHA.2464@.TK2MSFTNGP06.phx.gbl...
>> Id like to know when i have a query that returns say 12 million rows as
>> an example, is there an easy way to find out how much of data that is in
>> MB or GB ?
>> Thanks
>sql

Easy select distinct question.....

Dear Reader and Posters,
I have a quick question about the use of a select statement.
I have this big db tbl and I would like to be able to select rows of
data using (i think) distinct. Here is the tricky part... I would only
like to apply the distinct to one column in the table not the all the
columns. I have been reading around and people have been reluctant to
elaborate on other peoples questions that are alike mine because they
say that it makes no sense to do what I want to do because if there
are two rows of data and everything except one column is the same then
what says which one gets selected. My answer is that I don't care. Is
this possible and if so can any one point me in the right direction?
Thank,
dp
Hi
"C" wrote:

> Dear Reader and Posters,
> I have a quick question about the use of a select statement.
>
> I have this big db tbl and I would like to be able to select rows of
> data using (i think) distinct. Here is the tricky part... I would only
> like to apply the distinct to one column in the table not the all the
> columns. I have been reading around and people have been reluctant to
> elaborate on other peoples questions that are alike mine because they
> say that it makes no sense to do what I want to do because if there
> are two rows of data and everything except one column is the same then
> what says which one gets selected. My answer is that I don't care. Is
> this possible and if so can any one point me in the right direction?
>
> Thank,
> dp
If you don't care what the other values are then just take then why don't
you just take the maximum of the other values and group by the column you
want to be distinct?
If this has to be a specific row then use the maximum of the Primary Key and
get the row that corresponds to that e.g.
SELECT m.PK, m.Col1, m.COl2
FROM ( SELECT MAX(PK) AS PK, Col1 FROM MyTable GROUP BY Col1 ) s
JOIN MyTable m ON m.PK = s.PK
John
|||Hi dp,
how should that look like, onyl distincing to one column ? If you want
one row per Distinct value, you will have to aggregate the other
columns with aggregate expressions like:
SELECT A,MON(B),MIN(C)
FROM SoneTable
Group BY A --This is the Distinct Column
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de

Easy select distinct question.....

Dear Reader and Posters,
I have a quick question about the use of a select statement.
I have this big db tbl and I would like to be able to select rows of
data using (i think) distinct. Here is the tricky part... I would only
like to apply the distinct to one column in the table not the all the
columns. I have been reading around and people have been reluctant to
elaborate on other peoples questions that are alike mine because they
say that it makes no sense to do what I want to do because if there
are two rows of data and everything except one column is the same then
what says which one gets selected. My answer is that I don't care. Is
this possible and if so can any one point me in the right direction?
Thank,
dp"C" <devprog@.newfound.biz> wrote in message
news:1171701419.221382.33560@.k78g2000cwa.googlegroups.com...
> Dear Reader and Posters,
> I have a quick question about the use of a select statement.
>
> I have this big db tbl and I would like to be able to select rows of
> data using (i think) distinct. Here is the tricky part... I would only
> like to apply the distinct to one column in the table not the all the
> columns. I have been reading around and people have been reluctant to
> elaborate on other peoples questions that are alike mine because they
> say that it makes no sense to do what I want to do because if there
> are two rows of data and everything except one column is the same then
> what says which one gets selected. My answer is that I don't care. Is
> this possible and if so can any one point me in the right direction?
>
If your table t has a single-column key, say 'id', and you want one row for
each distinct value of a column c, then something like:
select *
from t
where t.id
(select min(id) from t group by c)
David|||Hi
"C" wrote:

> Dear Reader and Posters,
> I have a quick question about the use of a select statement.
>
> I have this big db tbl and I would like to be able to select rows of
> data using (i think) distinct. Here is the tricky part... I would only
> like to apply the distinct to one column in the table not the all the
> columns. I have been reading around and people have been reluctant to
> elaborate on other peoples questions that are alike mine because they
> say that it makes no sense to do what I want to do because if there
> are two rows of data and everything except one column is the same then
> what says which one gets selected. My answer is that I don't care. Is
> this possible and if so can any one point me in the right direction?
>
> Thank,
> dp
If you don't care what the other values are then just take then why don't
you just take the maximum of the other values and group by the column you
want to be distinct?
If this has to be a specific row then use the maximum of the Primary Key and
get the row that corresponds to that e.g.
SELECT m.PK, m.Col1, m.COl2
FROM ( SELECT MAX(PK) AS PK, Col1 FROM MyTable GROUP BY Col1 ) s
JOIN MyTable m ON m.PK = s.PK
John|||Hi dp,
how should that look like, onyl distincing to one column ? If you want
one row per Distinct value, you will have to aggregate the other
columns with aggregate expressions like:
SELECT A,MON(B),MIN(C)
FROM SoneTable
Group BY A --This is the Distinct Column
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de
--|||"Jens" <Jens@.sqlserver2005.de> wrote in message
news:1171733568.343342.33660@.q2g2000cwa.googlegroups.com...
> Hi dp,
> how should that look like, onyl distincing to one column ? If you want
> one row per Distinct value, you will have to aggregate the other
> columns with aggregate expressions like:
> SELECT A,MON(B),MIN(C)
> FROM SoneTable
> Group BY A --This is the Distinct Column
>
But this won't give you any particular row. It will be a "frankenstein" row
made up of bits of many rows.
David|||On Feb 17, 1:09 pm, "David Browne" <davidbaxterbrowne no potted
m...@.hotmail.com> wrote:
> "Jens" <J...@.sqlserver2005.de> wrote in message
> news:1171733568.343342.33660@.q2g2000cwa.googlegroups.com...
>
>
>
> But this won't give you any particular row. It will be a "frankenstein" r
ow
> made up of bits of many rows.
> David
Thanks all I will try things out... cdp|||"David Browne" <davidbaxterbrowne no potted meat@.hotmail.com> wrote in
message news:uBvFpcsUHHA.5100@.TK2MSFTNGP06.phx.gbl...
>.
> It will be a "frankenstein" row made up of bits of many rows.
Every once in a while there is real insight in this forum!
Now is it a 'Young Frankenstein', the mature 'Frankenstein' or
perhaps just the 'Ghost of Frankenstein'?
-

Thursday, March 22, 2012

Easy aggregation question

Given this table
CREATE TABLE SearchFieldDetail (ExpSetNo int, TableAlias char(10), Operator
char(2))
which has multiple rows for each ExpSetNo, I want to find each ExpSetNo that
has only one TableAlias among all of the same ExpSetNo rows and which has
'CC' as the Operator in all those rows.
I would only want to return ExpSetNo 1 from this data:
INSERT SearchFieldDetail
SELECT 1, 'COMCF', 'CC'
UNION
SELECT 1, 'COMCF', 'CC'
UNION
SELECT 2, 'COMCF', 'CC'
UNION
SELECT 2, 'COC', '='
UNION
SELECT 3, 'COC', 'CC'
UNION
SELECT 3, 'COMCF', 'CC'
And here's what I'm doing.
SELECT ExpSetNo
FROM SearchFieldDetail
GROUP BY ExpSetNo
HAVING COUNT(TableAlias) = 1 AND SUM(CASE Operator WHEN 'CC' THEN 0 ELSE 1
END) = 0
DROP TABLE SearchFieldDetail
This works, but are there any suggestions for improvement?> I want to find each ExpSetNo that
> has only one TableAlias among all of the same ExpSetNo rows
In this case, you need to add DISTINCT to your COUNT function like the
example below. Also, I believe your sample data insert query needs to
specify UNION ALL rather than UNION.
SELECT ExpSetNo
FROM SearchFieldDetail
GROUP BY ExpSetNo
HAVING COUNT(DISTINCT TableAlias) = 1 AND SUM(CASE Operator WHEN 'CC' THEN 0
ELSE 1
END) = 0
Hope this helps.
Dan Guzman
SQL Server MVP
"Mark Wilden" <mark@.mwilden.com> wrote in message
news:xqadnVdqk_RebmvcRVn-sg@.sti.net...
> Given this table
> CREATE TABLE SearchFieldDetail (ExpSetNo int, TableAlias char(10),
> Operator
> char(2))
> which has multiple rows for each ExpSetNo, I want to find each ExpSetNo
> that
> has only one TableAlias among all of the same ExpSetNo rows and which has
> 'CC' as the Operator in all those rows.
> I would only want to return ExpSetNo 1 from this data:
> INSERT SearchFieldDetail
> SELECT 1, 'COMCF', 'CC'
> UNION
> SELECT 1, 'COMCF', 'CC'
> UNION
> SELECT 2, 'COMCF', 'CC'
> UNION
> SELECT 2, 'COC', '='
> UNION
> SELECT 3, 'COC', 'CC'
> UNION
> SELECT 3, 'COMCF', 'CC'
> And here's what I'm doing.
> SELECT ExpSetNo
> FROM SearchFieldDetail
> GROUP BY ExpSetNo
> HAVING COUNT(TableAlias) = 1 AND SUM(CASE Operator WHEN 'CC' THEN 0 ELSE 1
> END) = 0
> DROP TABLE SearchFieldDetail
> This works, but are there any suggestions for improvement?
>
>|||"Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
news:eCvRsJ1AFHA.2104@.TK2MSFTNGP14.phx.gbl...
> In this case, you need to add DISTINCT to your COUNT function like the
> example below. Also, I believe your sample data insert query needs to
> specify UNION ALL rather than UNION.
> SELECT ExpSetNo
> FROM SearchFieldDetail
> GROUP BY ExpSetNo
> HAVING COUNT(DISTINCT TableAlias) = 1 AND SUM(CASE Operator WHEN 'CC' THEN
0
> ELSE 1
> END) = 0
Excellent, Dan - thanks. A good example of bad test data (created without
UNION ALL) giving misleading results.

easy (hopefully) matrix question


I'm working with a matrix in the designer and noticed I need to add a new row in between two existing rows. When I right click and choose add row a row is added at the very bottom of the matrix. What's the easiest way to add a matrix row to the middle of a matrix, one that doesn't include editing the rdl directly.

thanks

I had this exact problem!

What I found out is that if you carefully (yes, carefully) drag your field between 2 existing data fields, there's a thin white bracket line that shows up on the outside of the nearest existing textbox. This is to alert you where the field will be placed. It will either be on the left, right, top or bottom. If none of these areas are white then keep looking because otherwise you'll replace the destination cells - (bad).

|||Thanks for the response! I can insert a row below the first row but every other row is missing that white line that indicates I can insert.

Can you insert between every row or just between the first and second rows?|||You should be able to do it anywhere.. try moving the mouse around more.
The only time I see that you don't get the white bar is when you don't even have an existing data field in the nearest textbox.|||
You're right. After expanding the box and some very careful mouse work I got it to insert. Hopefully the MSFT guys will make this very basic function easier to use. Thanks again for the help.

Easy (?) data-editing solution? Need help pls.

I have several thousand rows of (text) data that have some incorrect pieces. I need a way to delete part of the data but leave the rest intact.

Example:

Current data: "Bloomfield, CT"

Needs to become: Bloomfield

In other words, I need to remove the left quote, and everything after (including) the comma.

there are dozens of different cities in the DB like this.

I can write the simple query that can pull out all of the data that has a comma, or quotes. What I don't seem to get is how to then "erase" the quotes (or the string that includes the comma and everything after it) and then update the DB with this new value.

Help?Most databases have a substring and in-string (or position string) function which you can use in combination to do parsing. My example is oriented to DB2:

SUBSTR(current_data, 2, POSSTR(current_data, ',') - 1)
Result would be Bloomfield

You can use the above in an UPDATE statement:
UPDATE table SET city = SUBSTR(current_data, 2, POSSTR(current_data, ',') - 1)

Originally posted by rexnervous
I have several thousand rows of (text) data that have some incorrect pieces. I need a way to delete part of the data but leave the rest intact.

Example:

Current data: "Bloomfield, CT"

Needs to become: Bloomfield

In other words, I need to remove the left quote, and everything after (including) the comma.

there are dozens of different cities in the DB like this.

I can write the simple query that can pull out all of the data that has a comma, or quotes. What I don't seem to get is how to then "erase" the quotes (or the string that includes the comma and everything after it) and then update the DB with this new value.

Help?|||Also, use the 'REPLACE' and 'GRATER' functions to eliminate the quotes:

UPDATE mytable
SET city = REPLACE(SUBSTR(city, 1
,GREATER(POSSTR(city, ',') - 1,LENGTH(city)))
,'"','')
WHERE POSSTR(city, ',') > 0
OR POSSTR(city, '"') > 0

:cool:|||Thanks you both, will give it a shot. Unfortunately, I'm using MS Access and it doesn't recognize those particular functions, but I think I can replace them.|||For Access take a look at Instr and Mid there is even a Replace. Have fun!

Originally posted by rexnervous
Thanks you both, will give it a shot. Unfortunately, I'm using MS Access and it doesn't recognize those particular functions, but I think I can replace them.

Monday, March 19, 2012

dynamically return rows 1-10, 11-20, 20-30 using select statement

Hi,
i would like to know if it is possible for me to get back the rows i am
interested in rather than all the records matching the query.
Right now my query returns first 20 items, 30 items or the first 500 items.
But i am having a problem with timeout when i query all 5000 items.
Can i get back only 10 items at a time in the order 1-10, 11-20, 20-30, etc.
Thanks
-SreeEssentially you are talking about paging your results into manageable
chunks'
Check out this article:
http://www.fawcette.com/dotnetmag/2...pf
.asp.
It is an implementation in .NET, but pay attention to the SQL portion of it.
--
HTH,
SriSamp
Please reply to the whole group only!
http://www32.brinkster.com/srisamp
"sree" <ss@.aa.com> wrote in message
news:r9b3c.89293$PR3.1286538@.attbi_s03...
> Hi,
> i would like to know if it is possible for me to get back the rows i am
> interested in rather than all the records matching the query.
> Right now my query returns first 20 items, 30 items or the first 500
items.
> But i am having a problem with timeout when i query all 5000 items.
> Can i get back only 10 items at a time in the order 1-10, 11-20, 20-30,
etc.
> Thanks
> -Sree
>

Dynamically removing table rows

How can I dynamically remove a table row if a value is blank?
(i.e. Address 2 is blank)If you select the entire table row in report designer, you will notice that
there is a Visibility.Hidden property for the table row. You can use an
expression that evaluates to a boolean value to dynamically hide a table row
then. E.g. =IsNothing(Fields!Address2.Value)
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"Terry" <Terry@.discussions.microsoft.com> wrote in message
news:7439822C-5022-43CA-ABC4-1A970D55AA7D@.microsoft.com...
> How can I dynamically remove a table row if a value is blank?
> (i.e. Address 2 is blank)|||Thank you.
However, I tried on several occasions to get help with columns and no one is
able to assist.
Could someone provide me with a basic understanding how to setup columns?
The columns will be used for mailing labels.
Your assistance is greatly appreciated.
"Robert Bruckner [MSFT]" wrote:
> If you select the entire table row in report designer, you will notice that
> there is a Visibility.Hidden property for the table row. You can use an
> expression that evaluates to a boolean value to dynamically hide a table row
> then. E.g. =IsNothing(Fields!Address2.Value)
> -- Robert
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Terry" <Terry@.discussions.microsoft.com> wrote in message
> news:7439822C-5022-43CA-ABC4-1A970D55AA7D@.microsoft.com...
> > How can I dynamically remove a table row if a value is blank?
> >
> > (i.e. Address 2 is blank)
>
>|||Not sure I understand your follow up question correctly. Are you asking
about dynamically hiding table columns in a report? Table columns have a
visibility property like table rows.
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"Terry" <Terry@.discussions.microsoft.com> wrote in message
news:5E4E4127-A82C-487C-8AB1-8B1D1B7D4C46@.microsoft.com...
> Thank you.
> However, I tried on several occasions to get help with columns and no one
> is
> able to assist.
> Could someone provide me with a basic understanding how to setup columns?
> The columns will be used for mailing labels.
> Your assistance is greatly appreciated.
> "Robert Bruckner [MSFT]" wrote:
>> If you select the entire table row in report designer, you will notice
>> that
>> there is a Visibility.Hidden property for the table row. You can use an
>> expression that evaluates to a boolean value to dynamically hide a table
>> row
>> then. E.g. =IsNothing(Fields!Address2.Value)
>> -- Robert
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>> "Terry" <Terry@.discussions.microsoft.com> wrote in message
>> news:7439822C-5022-43CA-ABC4-1A970D55AA7D@.microsoft.com...
>> > How can I dynamically remove a table row if a value is blank?
>> >
>> > (i.e. Address 2 is blank)
>>|||Dynamically removing table rows have been resolved.
Thank you for your assistance.
"Robert Bruckner [MSFT]" wrote:
> Not sure I understand your follow up question correctly. Are you asking
> about dynamically hiding table columns in a report? Table columns have a
> visibility property like table rows.
> -- Robert
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Terry" <Terry@.discussions.microsoft.com> wrote in message
> news:5E4E4127-A82C-487C-8AB1-8B1D1B7D4C46@.microsoft.com...
> > Thank you.
> >
> > However, I tried on several occasions to get help with columns and no one
> > is
> > able to assist.
> >
> > Could someone provide me with a basic understanding how to setup columns?
> >
> > The columns will be used for mailing labels.
> >
> > Your assistance is greatly appreciated.
> >
> > "Robert Bruckner [MSFT]" wrote:
> >
> >> If you select the entire table row in report designer, you will notice
> >> that
> >> there is a Visibility.Hidden property for the table row. You can use an
> >> expression that evaluates to a boolean value to dynamically hide a table
> >> row
> >> then. E.g. =IsNothing(Fields!Address2.Value)
> >>
> >> -- Robert
> >> This posting is provided "AS IS" with no warranties, and confers no
> >> rights.
> >>
> >>
> >> "Terry" <Terry@.discussions.microsoft.com> wrote in message
> >> news:7439822C-5022-43CA-ABC4-1A970D55AA7D@.microsoft.com...
> >> > How can I dynamically remove a table row if a value is blank?
> >> >
> >> > (i.e. Address 2 is blank)
> >>
> >>
> >>
>
>

Sunday, March 11, 2012

Dynamically delete a row from report

Hi,
I have a report containing some values. Surprise? :)
I want to delete rows containing values 0 and null from the report. I need
to include those rows to the sql query, but don't wan't them to be seen in
that particular table. Can the dynamic deletion of a row be done?
Thanks for helping the noobie!No problem anymore, I think.
I don't have to delete the row, instead I just use the filter in the table
to exclude the values I don't want to be shown...

Wednesday, March 7, 2012

dynamically binding button and controls on table rows.

Hi,

I am new to .NET world. I am using visual studio express.

I am developing website using ASP.NET and C#.

I want to add buttons dynamically on a table row on my web page.

For this I have written this code in "example.aspx" file

<asp:TableID="tblExample"GridLines="Both"BorderWidth="1"runat="server">

</asp:Table>

In my corresponding "example.aspx.cs" file i have written

TableRow tr = new TableRow();

.....................

.....................

TableCell tc3 = new TableCell();

tc3.Width = 120;

Button bt = new Button();

bt.Text = btnStop.Text;

bt.Width = 120;

bt.CommandArgument = lrs.IpAddress + ":" + lrs.PortNo;

bt.Click += newEventHandler(cmdStop_Click);

tc3.Controls.Add(bt);

tr.Cells.Add(tc3);

tblExample.Rows.Add(tr);

In my EventHandler "cmdStop_Click" I am trying to perform some action but on that particular row's data.

My page is also reloading after every 5 secs.

After clicking a button in a row, when page refreshes, I am getting this message in popup error message. also that entry is ommited(as per code in EventHandler)

"The Page cannot be refreshed without resending the information.

Click retry to resend the information again.

or click Cancel to return to the page that you were trying to view"

resetButton cancelButton

_

How to bind that button to particular row so that when I click on a button the action should be performed on that particular row's data.

Thanks

Smile

I think that if you visit this site, you will find quite a few very good instructional videos that will help you create your website.

http://asp.net/learn/videos/default.aspx?tabid=63

Your question is not really a SQL Server question, but more one of how to get started and learn ASP programming. Check out the site above.

Wednesday, February 15, 2012

Dynamic SQL delete query problem

Hi all--Given a query that returns ~557K rows on SQL Server 2005 SP1:

SELECT distinct(a.[Import_Date]),b.[Import_Date],
a.[OS_USERNAME],b.[OS_USERNAME],a.[USERNAME],b.[USERNAME],
a.[TIMESTAMP],b.[TIMESTAMP]
FROM [DBA_AUDIT_SESSION] a, [DBA_AUDIT_SESSION] b
where a.[OS_USERNAME]=b.[OS_USERNAME]
and a.[USERNAME]=b.[USERNAME]
and a.[TIMESTAMP]=b.[TIMESTAMP]
and a.[Import_Date]<b.[Import_Date]

On a table that has the following definition:

TABLE [dbo].[DBA_AUDIT_SESSION](
[Import_Date] [datetime] NULL,
[INSTANCE_NAME] [varchar](16) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[HOST_NAME] [varchar](64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[OS_USERNAME] [varchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[USERNAME] [varchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[USERHOST] [varchar](128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[TERMINAL] [varchar](255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[TIMESTAMP] [datetime] NULL,
[ACTION_NAME] [varchar](27) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[LOGOFF_TIME] [datetime] NULL,
[LOGOFF_LREAD] [float] NULL,
[LOGOFF_PREAD] [float] NULL,
[LOGOFF_LWRITE] [float] NULL,
[LOGOFF_DLOCK] [varchar](40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[SESSIONID] [float] NULL,
[RETURNCODE] [float] NULL,
[CLIENT_ID] [varchar](64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[SESSION_CPU] [float] NULL

I would like to delete duplicate data from this table and keep only the data with the latest Import_Date. I came up with the following delete statement:

delete FROM [DBA_AUDIT_SESSION]
FROM [DBA_AUDIT_SESSION] a,
inner join [DBA_AUDIT_SESSION] b
on a.[TIMESTAMP]=b.[TIMESTAMP]
where a.[Import_Date]<b.[Import_Date];

The command parses successfully, but I get the following runtime error:
'Table DBA_AUDIT_SESSION is ambiguous.'

Does anyone have suggestions on how to fix this delete statement?

Use the TSQL update/delete statement syntax sparingly. The TSQL specific syntax can produce unexpected results if used incorrectly or performance problems also. You can use the standard DELETE statement syntax like:

-- assumes that import_date is unique per timestamp

delete [DBA_AUDIT_SESSION]

where Import_Date < (select max(a.Import_Date) from [DBA_AUDIT_SESSION] as a

where a.TimeStamp = [DBA_AUDIT_SESSION].TimeStamp)

|||This seems to do the trick, and meets all the criteria for cleanup needed. Thanks!

Dynamic SQL colunms into rows

Im trying to write a SQL script that will turn the rows from one table into colunms. I'm using the sp_excutesql porceure and it keeps coming back with an error.

The problem is that i cant seem to be able to use @.parameter as a name when i try to dynamically create a column. Its a dynamic sql problem but i cant seem to get around it.

This is the problem line -- SELECT @.SQL ='ALTER TABLE tblHM21 ADD @.ColName varchar(50)'

Create Table tblHM21 (uidHM21uniqueidentifier);-- loop through tests to get bring back names of the rows-- --declare @.rowCountintdeclare @.iintset @.i = 1set @.rowCount = (SELECTCount(intTestTableRow)FROM tblHSTests)while @.i <= @.rowCount
Begindeclare @.ColumnNamenvarchar(50)set @.columnName = (Select strTestNamefrom tblHStestswhere intTestTableRow = @.i)declare @.SQLnvarchar(500)declare @.paramsnvarchar(4000)SELECT @.SQL ='ALTER TABLE tblHM21 ADD @.ColName varchar(50)'SELECT @.params = N'@.ColName nvarchar(50)'EXECsp_executesql @.SQL, @.params, @.ColumnNameprint @.iprint @.ColumnNameset @.i = @.i+1Endselect *from tblHM21Drop Table tblHM21
hi

put

set@.SQL ='ALTER TABLE tblHM21 ADD @.ColName varchar(50)'
set @.params = N'@.ColName nvarchar(50)'
 
and before  execute print @.sql
no need to send parameter individually
u can add parameter within the sql statement 

|||

i tried that. I'll try agian theyere might be something i missed but i dont think so.

I have tired eveything and have figured out that it cant be done. Sanson