Showing posts with label varchar. Show all posts
Showing posts with label varchar. Show all posts

Tuesday, March 27, 2012

enumerate suffixes and counts in varchar column

I have a column of VARCHAR values for which each value may contain one of
more dashes ("-" character). I would like T-SQL that enumerate all the
possible values following the FINAL dash character and counts the number of
occurrances of each and loads these into another table (2 col table :
Suffix[nvarchar] and Count[int])First, the obligitory note of reason. Storing data like this is generally a
bad idea. If you need to use substring on a value then it probably needs to
be > 1 columns. Maybe not in your case, but I figure that the dashes aren't
a random pattern, right?
Second, this will give you the result, I think...
create table test
(
value varchar(20)
)
insert into test
select 'hds-f-dsafsaf-asf'
union all
select 'asdfasdfads'
union all
select 'asdfads-asdfas-as'
union all
select 'isd-asd'
go
select case when charindex('-',value) > 0 then
substring(reverse(value),1,charindex('-',reverse(value))-1)
else ''
end
from test
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"Arguments are to be avoided: they are always vulgar and often convincing."
(Oscar Wilde)
"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:Oxjgp2QLGHA.904@.TK2MSFTNGP10.phx.gbl...
>I have a column of VARCHAR values for which each value may contain one of
>more dashes ("-" character). I would like T-SQL that enumerate all the
>possible values following the FINAL dash character and counts the number of
>occurrances of each and loads these into another table (2 col table :
>Suffix[nvarchar] and Count[int])
>|||Yes, I agree. Very bad data structure. Not my idea.
You're code looks interesting, but I also need a count of each distinct
suffix (where a distinct suffix is defined as one that follows the final
dash ("-") character.
"Louis Davidson" <dr_dontspamme_sql@.hotmail.com> wrote in message
news:%23hLtR%23QLGHA.2416@.TK2MSFTNGP15.phx.gbl...
> First, the obligitory note of reason. Storing data like this is generally
> a bad idea. If you need to use substring on a value then it probably
> needs to be > 1 columns. Maybe not in your case, but I figure that the
> dashes aren't a random pattern, right?
> Second, this will give you the result, I think...
> create table test
> (
> value varchar(20)
> )
> insert into test
> select 'hds-f-dsafsaf-asf'
> union all
> select 'asdfasdfads'
> union all
> select 'asdfads-asdfas-as'
> union all
> select 'isd-asd'
> go
> select case when charindex('-',value) > 0 then
> substring(reverse(value),1,charindex('-',reverse(value))-1)
> else ''
> end
> from test
>
> --
> ----
--
> Louis Davidson - http://spaces.msn.com/members/drsql/
> SQL Server MVP
> "Arguments are to be avoided: they are always vulgar and often
> convincing."
> (Oscar Wilde)
> "John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
> news:Oxjgp2QLGHA.904@.TK2MSFTNGP10.phx.gbl...
>|||Here is the complete solution. Hope this helps get you going...
create table test
(
value varchar(20)
)
insert into test
select 'hds-f-dsafsaf-asf'
union all
select 'asdfasdfads'
union all
select 'asdfads-asdfas-as'
union all
select 'isd-asd'
union all
select 'isd3-asdfa-asd'
go
select suffix, count(*)
from ( select reverse(case when charindex('-',value) > 0 then
substring(reverse(value),1,charindex('-',reverse(value))-1)
else ''
end) as suffix
from test ) as suffixValues
group by suffix
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"Arguments are to be avoided: they are always vulgar and often convincing."
(Oscar Wilde)
"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:uhJPFDRLGHA.2668@.tk2msftngp13.phx.gbl...
> Yes, I agree. Very bad data structure. Not my idea.
> You're code looks interesting, but I also need a count of each distinct
> suffix (where a distinct suffix is defined as one that follows the final
> dash ("-") character.
>
> "Louis Davidson" <dr_dontspamme_sql@.hotmail.com> wrote in message
> news:%23hLtR%23QLGHA.2416@.TK2MSFTNGP15.phx.gbl...
>

Sunday, February 26, 2012

Enterprise Manager data entry limit

I have a table that has several fields of data type varchar
(4000). I cannot enter more that 1024 characters using
Enterprise Manager. I can create a table in Access and
import it or use VB to populate the table without any
problem. Why doesn't EM allow data to be entered up to the
field length in the table design?
Hi,
Sorry to tell this.
Enterprise manager is a GUI tool to do database administration, it is not a
tool to do data entry. You can very well
use Query Analyzer to insert the text data into a table using INSERT
statement.
Insert into table_name values('jhsajdhaskdlksadhsalkdjsaldjlsadjlsajdjl.. .n
characters)
Thanks
Hari
MCDBA
"Colin" <anonymous@.discussions.microsoft.com> wrote in message
news:1db6a01c4546c$17824130$a101280a@.phx.gbl...
> I have a table that has several fields of data type varchar
> (4000). I cannot enter more that 1024 characters using
> Enterprise Manager. I can create a table in Access and
> import it or use VB to populate the table without any
> problem. Why doesn't EM allow data to be entered up to the
> field length in the table design?
|||Colin,
I don't know the answer to your question, perhaps its a limit of the
grid control that is used? I have a question for you. Why do you want to
insert such huge values through Enterprise Manager? Why not just write a
quick script in Query Analyzer to insert the data?
Also beware that you could run into problems if all your field lengths
exceed the size of a data page (8k).
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Colin wrote:
> I have a table that has several fields of data type varchar
> (4000). I cannot enter more that 1024 characters using
> Enterprise Manager. I can create a table in Access and
> import it or use VB to populate the table without any
> problem. Why doesn't EM allow data to be entered up to the
> field length in the table design?
|||Thanks for the replies.
I understand EM is not the tool to use for data
entry...just curious why it limited data entry in this
way.
|||Hi Colin,
I've been chatting with the SQL MVPs and some people at Microsoft about
this issue on your behalf, and I was told to RTFM. :-) SQL MVP, Steve
Kass pointed this out to me:
"Some of the limitations of Enterprise Manager are documented in the
following Books Online article:
Editing Rows in the Results Pane
In particular, that article says:
You can edit a memo-type column (such as a text, memo, or long character
column) if the column does not display <Long Text>. The Results pane can
accept up to 900 characters of text in memo-type columns. If you are
typing in a cell and exceed the amount of text that the Results pane can
accept, the Query Designer will beep to indicate that you have exceeded
this limit."
I hope this helps further.
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Colin wrote:
> Thanks for the replies.
> I understand EM is not the tool to use for data
> entry...just curious why it limited data entry in this
> way.

Enterprise Manager data entry limit

I have a table that has several fields of data type varchar
(4000). I cannot enter more that 1024 characters using
Enterprise Manager. I can create a table in Access and
import it or use VB to populate the table without any
problem. Why doesn't EM allow data to be entered up to the
field length in the table design?Hi,
Sorry to tell this.
Enterprise manager is a GUI tool to do database administration, it is not a
tool to do data entry. You can very well
use Query Analyzer to insert the text data into a table using INSERT
statement.
Insert into table_name values('jhsajdhaskdlksadhsalkdjsaldjlsad
jlsajdjl...n
characters)
Thanks
Hari
MCDBA
"Colin" <anonymous@.discussions.microsoft.com> wrote in message
news:1db6a01c4546c$17824130$a101280a@.phx
.gbl...
> I have a table that has several fields of data type varchar
> (4000). I cannot enter more that 1024 characters using
> Enterprise Manager. I can create a table in Access and
> import it or use VB to populate the table without any
> problem. Why doesn't EM allow data to be entered up to the
> field length in the table design?|||Colin,
I don't know the answer to your question, perhaps its a limit of the
grid control that is used? I have a question for you. Why do you want to
insert such huge values through Enterprise Manager? Why not just write a
quick script in Query Analyzer to insert the data?
Also beware that you could run into problems if all your field lengths
exceed the size of a data page (8k).
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Colin wrote:
> I have a table that has several fields of data type varchar
> (4000). I cannot enter more that 1024 characters using
> Enterprise Manager. I can create a table in Access and
> import it or use VB to populate the table without any
> problem. Why doesn't EM allow data to be entered up to the
> field length in the table design?|||Thanks for the replies.
I understand EM is not the tool to use for data
entry...just curious why it limited data entry in this
way.|||Hi Colin,
I've been chatting with the SQL MVPs and some people at Microsoft about
this issue on your behalf, and I was told to RTFM. :-) SQL MVP, Steve
Kass pointed this out to me:
"Some of the limitations of Enterprise Manager are documented in the
following Books Online article:
Editing Rows in the Results Pane
In particular, that article says:
You can edit a memo-type column (such as a text, memo, or long character
column) if the column does not display <Long Text>. The Results pane can
accept up to 900 characters of text in memo-type columns. If you are
typing in a cell and exceed the amount of text that the Results pane can
accept, the Query Designer will beep to indicate that you have exceeded
this limit."
I hope this helps further.
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Colin wrote:
> Thanks for the replies.
> I understand EM is not the tool to use for data
> entry...just curious why it limited data entry in this
> way.

Enterprise Manager data entry limit

I have a table that has several fields of data type varchar
(4000). I cannot enter more that 1024 characters using
Enterprise Manager. I can create a table in Access and
import it or use VB to populate the table without any
problem. Why doesn't EM allow data to be entered up to the
field length in the table design?Hi,
Sorry to tell this.
Enterprise manager is a GUI tool to do database administration, it is not a
tool to do data entry. You can very well
use Query Analyzer to insert the text data into a table using INSERT
statement.
Insert into table_name values('jhsajdhaskdlksadhsalkdjsaldjlsadjlsajdjl...n
characters)
Thanks
Hari
MCDBA
"Colin" <anonymous@.discussions.microsoft.com> wrote in message
news:1db6a01c4546c$17824130$a101280a@.phx.gbl...
> I have a table that has several fields of data type varchar
> (4000). I cannot enter more that 1024 characters using
> Enterprise Manager. I can create a table in Access and
> import it or use VB to populate the table without any
> problem. Why doesn't EM allow data to be entered up to the
> field length in the table design?|||Colin,
I don't know the answer to your question, perhaps its a limit of the
grid control that is used? I have a question for you. Why do you want to
insert such huge values through Enterprise Manager? Why not just write a
quick script in Query Analyzer to insert the data?
Also beware that you could run into problems if all your field lengths
exceed the size of a data page (8k).
--
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Colin wrote:
> I have a table that has several fields of data type varchar
> (4000). I cannot enter more that 1024 characters using
> Enterprise Manager. I can create a table in Access and
> import it or use VB to populate the table without any
> problem. Why doesn't EM allow data to be entered up to the
> field length in the table design?|||Thanks for the replies.
I understand EM is not the tool to use for data
entry...just curious why it limited data entry in this
way.|||Hi Colin,
I've been chatting with the SQL MVPs and some people at Microsoft about
this issue on your behalf, and I was told to RTFM. :-) SQL MVP, Steve
Kass pointed this out to me:
"Some of the limitations of Enterprise Manager are documented in the
following Books Online article:
Editing Rows in the Results Pane
In particular, that article says:
You can edit a memo-type column (such as a text, memo, or long character
column) if the column does not display <Long Text>. The Results pane can
accept up to 900 characters of text in memo-type columns. If you are
typing in a cell and exceed the amount of text that the Results pane can
accept, the Query Designer will beep to indicate that you have exceeded
this limit."
I hope this helps further.
--
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Colin wrote:
> Thanks for the replies.
> I understand EM is not the tool to use for data
> entry...just curious why it limited data entry in this
> way.|||Can one of you experts give me some solutions?
We have small web-based sale order system linked to SQL server. One of the web page fields: "Remark" field only accepts 250 characters.
On the web page, the Remark field will let you type more than 250 characters. However, it only display maximum 250 characters in print preview. Any solutions?
Thank you in advance for any sugguestions.
"Colin" wrote:
> I have a table that has several fields of data type varchar
> (4000). I cannot enter more that 1024 characters using
> Enterprise Manager. I can create a table in Access and
> import it or use VB to populate the table without any
> problem. Why doesn't EM allow data to be entered up to the
> field length in the table design?
>

Wednesday, February 15, 2012

Entering a row from a table to a column of other table

Is it possible to enter a complete record into a column say varchar(max) and then be able to retreive the record from the column. I am using sql 2005.

Thanks very much in advance,

you can use a separator for columns and insert it into a table.

insert into tablename (varcharnmaxcolumn)

select col1 +'|' + col2+'|' +col3

from table1

and during retrieval you can split the output as per separator as '|' in this case