Hi,
I am very new to SQL and made a dumb mistake when setting up my
database. I have some small tables I used for drop-down-lists in a web
page I designed. I used a datatype of CHAR. Well, I should have used
VARCHAR as it is causing me problems now.
I have redesigned the site so the drop-down-lists are not pulled from
the SQL table. The problem is that every record created with one of
these dropdown values has trailing spaces. In other words, if the field
was CHAR with length 10 when we store Canada, it is really
Canada<space><space><space><space>.
I have found one way to fix this:
UPDATE mytable
SET country='Canada' WHERE country='Canada'
This has the effect of removing the spaces. I guess I could also use:
UPDATE mytable
SET country='Canada' WHERE country LIKE '%Canada%'
This is WAY too tedious to do for every value of every column I have
this problem with. Is there a way to iterate through the database a
remove ALL trailing spaces?
I appreciate the help!So you have changed the datatype in the table and want to get rid of the tra
iling spaces in the
varchar column?
UPDATE tblname
SET col = RTRIM(col)
Pls test above first, just in case...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
<mattmerc@.bellsouth.net> wrote in message
news:1124996454.969917.40520@.o13g2000cwo.googlegroups.com...
> Hi,
> I am very new to SQL and made a dumb mistake when setting up my
> database. I have some small tables I used for drop-down-lists in a web
> page I designed. I used a datatype of CHAR. Well, I should have used
> VARCHAR as it is causing me problems now.
> I have redesigned the site so the drop-down-lists are not pulled from
> the SQL table. The problem is that every record created with one of
> these dropdown values has trailing spaces. In other words, if the field
> was CHAR with length 10 when we store Canada, it is really
> Canada<space><space><space><space>.
> I have found one way to fix this:
> UPDATE mytable
> SET country='Canada' WHERE country='Canada'
> This has the effect of removing the spaces. I guess I could also use:
> UPDATE mytable
> SET country='Canada' WHERE country LIKE '%Canada%'
> This is WAY too tedious to do for every value of every column I have
> this problem with. Is there a way to iterate through the database a
> remove ALL trailing spaces?
> I appreciate the help!
>|||I read about RTRIM but didn't realize it could be used that way. I will
test it. Thanks!
Tibor Karaszi wrote:
> So you have changed the datatype in the table and want to get rid of the t
railing spaces in the
> varchar column?
> UPDATE tblname
> SET col = RTRIM(col)
> Pls test above first, just in case...
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> <mattmerc@.bellsouth.net> wrote in message
> news:1124996454.969917.40520@.o13g2000cwo.googlegroups.com...|||First, in Enterprise Manager you need to redefine the Char(10) column as
VarChar(30), becuase Char columns cannot be trimmed. The rtrim() function
will returns a string with trailing spaces trimmed. You will probably want
to trim every country in the table, so there is no need to specify a where
clause.
UPDATE mytable SET country = rtrim(country)
http://sqlcourse.com/create.html
http://sqlcourse.com/update.html
<mattmerc@.bellsouth.net> wrote in message
news:1124996454.969917.40520@.o13g2000cwo.googlegroups.com...
> Hi,
> I am very new to SQL and made a dumb mistake when setting up my
> database. I have some small tables I used for drop-down-lists in a web
> page I designed. I used a datatype of CHAR. Well, I should have used
> VARCHAR as it is causing me problems now.
> I have redesigned the site so the drop-down-lists are not pulled from
> the SQL table. The problem is that every record created with one of
> these dropdown values has trailing spaces. In other words, if the field
> was CHAR with length 10 when we store Canada, it is really
> Canada<space><space><space><space>.
> I have found one way to fix this:
> UPDATE mytable
> SET country='Canada' WHERE country='Canada'
> This has the effect of removing the spaces. I guess I could also use:
> UPDATE mytable
> SET country='Canada' WHERE country LIKE '%Canada%'
> This is WAY too tedious to do for every value of every column I have
> this problem with. Is there a way to iterate through the database a
> remove ALL trailing spaces?
> I appreciate the help!
>|||You can also use the RTRIM() function, but this still require you to update
every column. Although it might be easier to drop, recreate the tables
using varchar, and reload them.
--Brian
(Please reply to the newsgroups only.)
<mattmerc@.bellsouth.net> wrote in message
news:1124996454.969917.40520@.o13g2000cwo.googlegroups.com...
> Hi,
> I am very new to SQL and made a dumb mistake when setting up my
> database. I have some small tables I used for drop-down-lists in a web
> page I designed. I used a datatype of CHAR. Well, I should have used
> VARCHAR as it is causing me problems now.
> I have redesigned the site so the drop-down-lists are not pulled from
> the SQL table. The problem is that every record created with one of
> these dropdown values has trailing spaces. In other words, if the field
> was CHAR with length 10 when we store Canada, it is really
> Canada<space><space><space><space>.
> I have found one way to fix this:
> UPDATE mytable
> SET country='Canada' WHERE country='Canada'
> This has the effect of removing the spaces. I guess I could also use:
> UPDATE mytable
> SET country='Canada' WHERE country LIKE '%Canada%'
> This is WAY too tedious to do for every value of every column I have
> this problem with. Is there a way to iterate through the database a
> remove ALL trailing spaces?
> I appreciate the help!
>
Showing posts with label webpage. Show all posts
Showing posts with label webpage. Show all posts
Monday, March 26, 2012
Friday, March 23, 2012
problem queryplan xml template query
Hi,
I use a xsd schema to load XML with a complex structure from a database for
using it in an ASP webpage. Somehow the database uses quite a long time to
make a query plan for the template. The second time the template is used the
database responses quickly, also for other data (using other selection
criteria).
The queryplan is lost when there are no calls for some time, or when a small
change is made to de database stucture, so the next time the ASP page is
called users receive a timeout error.
I have checked all the relevant indexes from the tables that are used for
creating the XML.
Is there any way to influence the speed/persistance of the queryplan that is
created for a xml template query?
Any help will be appreceated,
Albert JanI don't think there is. What is happening is that the first time the query
is compiled and then cached. If you don't run it for a while, the query plan
will be purged from the cache and the query will be recompiled. The only way
to "persist" the plan is to write the FOR XML EXPLICIT mode query inside a
stored proc and call the stored proc. You can use the SQL Profiler to see
what the query is that is being generated.
Best regards
Michael
"Albert Jan" <awonnink@.hotmail.com> wrote in message
news:O$EwS3POFHA.4028@.tk2msftngp13.phx.gbl...
> Hi,
> I use a xsd schema to load XML with a complex structure from a database
> for
> using it in an ASP webpage. Somehow the database uses quite a long time to
> make a query plan for the template. The second time the template is used
> the
> database responses quickly, also for other data (using other selection
> criteria).
> The queryplan is lost when there are no calls for some time, or when a
> small
> change is made to de database stucture, so the next time the ASP page is
> called users receive a timeout error.
> I have checked all the relevant indexes from the tables that are used for
> creating the XML.
> Is there any way to influence the speed/persistance of the queryplan that
> is
> created for a xml template query?
> Any help will be appreceated,
> Albert Jan
>|||Hi Michael,
I had hoped I woudn't have to redesign the solution, because I like the
technique using the template query. But maybe I'll just have to.
Thank you for your answer.
Albert Jan
"Michael Rys [MSFT]" <mrys@.online.microsoft.com> wrote in message
news:emXkJcUOFHA.3808@.TK2MSFTNGP14.phx.gbl...
> I don't think there is. What is happening is that the first time the query
> is compiled and then cached. If you don't run it for a while, the query
plan
> will be purged from the cache and the query will be recompiled. The only
way
> to "persist" the plan is to write the FOR XML EXPLICIT mode query inside a
> stored proc and call the stored proc. You can use the SQL Profiler to see
> what the query is that is being generated.
> Best regards
> Michael
> "Albert Jan" <awonnink@.hotmail.com> wrote in message
> news:O$EwS3POFHA.4028@.tk2msftngp13.phx.gbl...
to
for
that
>
>
I use a xsd schema to load XML with a complex structure from a database for
using it in an ASP webpage. Somehow the database uses quite a long time to
make a query plan for the template. The second time the template is used the
database responses quickly, also for other data (using other selection
criteria).
The queryplan is lost when there are no calls for some time, or when a small
change is made to de database stucture, so the next time the ASP page is
called users receive a timeout error.
I have checked all the relevant indexes from the tables that are used for
creating the XML.
Is there any way to influence the speed/persistance of the queryplan that is
created for a xml template query?
Any help will be appreceated,
Albert JanI don't think there is. What is happening is that the first time the query
is compiled and then cached. If you don't run it for a while, the query plan
will be purged from the cache and the query will be recompiled. The only way
to "persist" the plan is to write the FOR XML EXPLICIT mode query inside a
stored proc and call the stored proc. You can use the SQL Profiler to see
what the query is that is being generated.
Best regards
Michael
"Albert Jan" <awonnink@.hotmail.com> wrote in message
news:O$EwS3POFHA.4028@.tk2msftngp13.phx.gbl...
> Hi,
> I use a xsd schema to load XML with a complex structure from a database
> for
> using it in an ASP webpage. Somehow the database uses quite a long time to
> make a query plan for the template. The second time the template is used
> the
> database responses quickly, also for other data (using other selection
> criteria).
> The queryplan is lost when there are no calls for some time, or when a
> small
> change is made to de database stucture, so the next time the ASP page is
> called users receive a timeout error.
> I have checked all the relevant indexes from the tables that are used for
> creating the XML.
> Is there any way to influence the speed/persistance of the queryplan that
> is
> created for a xml template query?
> Any help will be appreceated,
> Albert Jan
>|||Hi Michael,
I had hoped I woudn't have to redesign the solution, because I like the
technique using the template query. But maybe I'll just have to.
Thank you for your answer.
Albert Jan
"Michael Rys [MSFT]" <mrys@.online.microsoft.com> wrote in message
news:emXkJcUOFHA.3808@.TK2MSFTNGP14.phx.gbl...
> I don't think there is. What is happening is that the first time the query
> is compiled and then cached. If you don't run it for a while, the query
plan
> will be purged from the cache and the query will be recompiled. The only
way
> to "persist" the plan is to write the FOR XML EXPLICIT mode query inside a
> stored proc and call the stored proc. You can use the SQL Profiler to see
> what the query is that is being generated.
> Best regards
> Michael
> "Albert Jan" <awonnink@.hotmail.com> wrote in message
> news:O$EwS3POFHA.4028@.tk2msftngp13.phx.gbl...
to
for
that
>
>
problem queryplan xml template query
Hi,
I use a xsd schema to load XML with a complex structure from a database for
using it in an ASP webpage. Somehow the database uses quite a long time to
make a query plan for the template. The second time the template is used the
database responses quickly, also for other data (using other selection
criteria).
The queryplan is lost when there are no calls for some time, or when a small
change is made to de database stucture, so the next time the ASP page is
called users receive a timeout error.
I have checked all the relevant indexes from the tables that are used for
creating the XML.
Is there any way to influence the speed/persistance of the queryplan that is
created for a xml template query?
Any help will be appreceated,
Albert Jan
I don't think there is. What is happening is that the first time the query
is compiled and then cached. If you don't run it for a while, the query plan
will be purged from the cache and the query will be recompiled. The only way
to "persist" the plan is to write the FOR XML EXPLICIT mode query inside a
stored proc and call the stored proc. You can use the SQL Profiler to see
what the query is that is being generated.
Best regards
Michael
"Albert Jan" <awonnink@.hotmail.com> wrote in message
news:O$EwS3POFHA.4028@.tk2msftngp13.phx.gbl...
> Hi,
> I use a xsd schema to load XML with a complex structure from a database
> for
> using it in an ASP webpage. Somehow the database uses quite a long time to
> make a query plan for the template. The second time the template is used
> the
> database responses quickly, also for other data (using other selection
> criteria).
> The queryplan is lost when there are no calls for some time, or when a
> small
> change is made to de database stucture, so the next time the ASP page is
> called users receive a timeout error.
> I have checked all the relevant indexes from the tables that are used for
> creating the XML.
> Is there any way to influence the speed/persistance of the queryplan that
> is
> created for a xml template query?
> Any help will be appreceated,
> Albert Jan
>
|||Hi Michael,
I had hoped I woudn't have to redesign the solution, because I like the
technique using the template query. But maybe I'll just have to.
Thank you for your answer.
Albert Jan
"Michael Rys [MSFT]" <mrys@.online.microsoft.com> wrote in message
news:emXkJcUOFHA.3808@.TK2MSFTNGP14.phx.gbl...
> I don't think there is. What is happening is that the first time the query
> is compiled and then cached. If you don't run it for a while, the query
plan
> will be purged from the cache and the query will be recompiled. The only
way[vbcol=seagreen]
> to "persist" the plan is to write the FOR XML EXPLICIT mode query inside a
> stored proc and call the stored proc. You can use the SQL Profiler to see
> what the query is that is being generated.
> Best regards
> Michael
> "Albert Jan" <awonnink@.hotmail.com> wrote in message
> news:O$EwS3POFHA.4028@.tk2msftngp13.phx.gbl...
to[vbcol=seagreen]
for[vbcol=seagreen]
that
>
>
sql
I use a xsd schema to load XML with a complex structure from a database for
using it in an ASP webpage. Somehow the database uses quite a long time to
make a query plan for the template. The second time the template is used the
database responses quickly, also for other data (using other selection
criteria).
The queryplan is lost when there are no calls for some time, or when a small
change is made to de database stucture, so the next time the ASP page is
called users receive a timeout error.
I have checked all the relevant indexes from the tables that are used for
creating the XML.
Is there any way to influence the speed/persistance of the queryplan that is
created for a xml template query?
Any help will be appreceated,
Albert Jan
I don't think there is. What is happening is that the first time the query
is compiled and then cached. If you don't run it for a while, the query plan
will be purged from the cache and the query will be recompiled. The only way
to "persist" the plan is to write the FOR XML EXPLICIT mode query inside a
stored proc and call the stored proc. You can use the SQL Profiler to see
what the query is that is being generated.
Best regards
Michael
"Albert Jan" <awonnink@.hotmail.com> wrote in message
news:O$EwS3POFHA.4028@.tk2msftngp13.phx.gbl...
> Hi,
> I use a xsd schema to load XML with a complex structure from a database
> for
> using it in an ASP webpage. Somehow the database uses quite a long time to
> make a query plan for the template. The second time the template is used
> the
> database responses quickly, also for other data (using other selection
> criteria).
> The queryplan is lost when there are no calls for some time, or when a
> small
> change is made to de database stucture, so the next time the ASP page is
> called users receive a timeout error.
> I have checked all the relevant indexes from the tables that are used for
> creating the XML.
> Is there any way to influence the speed/persistance of the queryplan that
> is
> created for a xml template query?
> Any help will be appreceated,
> Albert Jan
>
|||Hi Michael,
I had hoped I woudn't have to redesign the solution, because I like the
technique using the template query. But maybe I'll just have to.
Thank you for your answer.
Albert Jan
"Michael Rys [MSFT]" <mrys@.online.microsoft.com> wrote in message
news:emXkJcUOFHA.3808@.TK2MSFTNGP14.phx.gbl...
> I don't think there is. What is happening is that the first time the query
> is compiled and then cached. If you don't run it for a while, the query
plan
> will be purged from the cache and the query will be recompiled. The only
way[vbcol=seagreen]
> to "persist" the plan is to write the FOR XML EXPLICIT mode query inside a
> stored proc and call the stored proc. You can use the SQL Profiler to see
> what the query is that is being generated.
> Best regards
> Michael
> "Albert Jan" <awonnink@.hotmail.com> wrote in message
> news:O$EwS3POFHA.4028@.tk2msftngp13.phx.gbl...
to[vbcol=seagreen]
for[vbcol=seagreen]
that
>
>
sql
Subscribe to:
Posts (Atom)