Showing posts with label examples. Show all posts
Showing posts with label examples. Show all posts

Sunday, March 11, 2012

Declare Variable Dynamically

I'm attempting to modify some Crosstab generating code, and I need some
advice/examples.

Currently, the code uses a single string variable to store the
dynamically generated query (www.johnmacintyre.ca). The problem is that
I am trying to pivot biological taxonomy information, and may end up
with a table containing over 200 columns. This takes the dynamic string
well over the 8000char limit for variables.

>From my understanding, the EXEC() command does not have the 8000char
limit if the execution string is broken into chunks, and concatenated
e.g. EXEC(sql1 + sql2 + sql3 + ...). So the solution I think I need is
to:

1) start a counter at the beginining of the dynamic generation
2) append the counter value to the end of a string variable name
3) DECLARE the new variable and attach that loop cycle of text to it,
or attach each chunk of characters < 8000
4) build the EXEC() string by concatenating each dynamic varible

Can this be done? Should it be done? Is there a better way to address
this type of problem?

Thanks for any ideas or insights

Tim Pascoe>> Can this be done? <<

Maybe, maybe not.

>> Should it be done? <<

No, this is a mis-use of SQL.

>> Is there a better way to address this type of problem? <<

Crosstabs (thank you for not calling them "pivot tables") are a report
and not a query. you ought to use a report tool and not SQL for this
kind of job.|||Hi
You may want to look at previous posts regarding crosstab queries, as Joe
says it is better to do this in the reporting tool such as RAC
http://www.rac4sql.net/ and others.

Here are a few links you may want to read:
http://www.windowsitpro.com/SQLServ...5608/15608.html
http://support.microsoft.com/defaul...b;EN-US;q175574

http://www.sqlteam.com/item.asp?ItemID=2955

John

<tim.pascoe@.cciw.ca> wrote in message
news:1102971154.140806.89470@.f14g2000cwb.googlegro ups.com...
> I'm attempting to modify some Crosstab generating code, and I need some
> advice/examples.
> Currently, the code uses a single string variable to store the
> dynamically generated query (www.johnmacintyre.ca). The problem is that
> I am trying to pivot biological taxonomy information, and may end up
> with a table containing over 200 columns. This takes the dynamic string
> well over the 8000char limit for variables.
>>From my understanding, the EXEC() command does not have the 8000char
> limit if the execution string is broken into chunks, and concatenated
> e.g. EXEC(sql1 + sql2 + sql3 + ...). So the solution I think I need is
> to:
> 1) start a counter at the beginining of the dynamic generation
> 2) append the counter value to the end of a string variable name
> 3) DECLARE the new variable and attach that loop cycle of text to it,
> or attach each chunk of characters < 8000
> 4) build the EXEC() string by concatenating each dynamic varible
> Can this be done? Should it be done? Is there a better way to address
> this type of problem?
> Thanks for any ideas or insights
> Tim Pascoe|||RAC was my next point of investigation. The problem is that I'm not
actually producing a report of the data (although I agree this is
generally what crosstabs are for). Instead, the data is required in
this format so it can be fed into statistical software, which requires
the crosstabulated structure. I'll look into RAC and the other sites
you listed.

Thanks.

John Bell wrote:
> Hi
> You may want to look at previous posts regarding crosstab queries, as
Joe
> says it is better to do this in the reporting tool such as RAC
> http://www.rac4sql.net/ and others.
> Here are a few links you may want to read:
http://www.windowsitpro.com/SQLServ...5608/15608.html
> http://support.microsoft.com/defaul...b;EN-US;q175574
> http://www.sqlteam.com/item.asp?ItemID=2955
> John
> <tim.pascoe@.cciw.ca> wrote in message
> news:1102971154.140806.89470@.f14g2000cwb.googlegro ups.com...
> > I'm attempting to modify some Crosstab generating code, and I need
some
> > advice/examples.
> > Currently, the code uses a single string variable to store the
> > dynamically generated query (www.johnmacintyre.ca). The problem is
that
> > I am trying to pivot biological taxonomy information, and may end
up
> > with a table containing over 200 columns. This takes the dynamic
string
> > well over the 8000char limit for variables.
> >>From my understanding, the EXEC() command does not have the
8000char
> > limit if the execution string is broken into chunks, and
concatenated
> > e.g. EXEC(sql1 + sql2 + sql3 + ...). So the solution I think I need
is
> > to:
> > 1) start a counter at the beginining of the dynamic generation
> > 2) append the counter value to the end of a string variable name
> > 3) DECLARE the new variable and attach that loop cycle of text to
it,
> > or attach each chunk of characters < 8000
> > 4) build the EXEC() string by concatenating each dynamic varible
> > Can this be done? Should it be done? Is there a better way to
address
> > this type of problem?
> > Thanks for any ideas or insights
> > Tim Pascoe|||Hi

You may want to consider Analysis services then?

John

<tim.pascoe@.cciw.ca> wrote in message
news:1103032212.575699.29580@.c13g2000cwb.googlegro ups.com...
> RAC was my next point of investigation. The problem is that I'm not
> actually producing a report of the data (although I agree this is
> generally what crosstabs are for). Instead, the data is required in
> this format so it can be fed into statistical software, which requires
> the crosstabulated structure. I'll look into RAC and the other sites
> you listed.
> Thanks.
>
> John Bell wrote:
>> Hi
>> You may want to look at previous posts regarding crosstab queries, as
> Joe
>> says it is better to do this in the reporting tool such as RAC
>> http://www.rac4sql.net/ and others.
>>
>> Here are a few links you may want to read:
>>
> http://www.windowsitpro.com/SQLServ...5608/15608.html
>> http://support.microsoft.com/defaul...b;EN-US;q175574
>>
>> http://www.sqlteam.com/item.asp?ItemID=2955
>>
>> John
>>
>> <tim.pascoe@.cciw.ca> wrote in message
>> news:1102971154.140806.89470@.f14g2000cwb.googlegro ups.com...
>> > I'm attempting to modify some Crosstab generating code, and I need
> some
>> > advice/examples.
>>> > Currently, the code uses a single string variable to store the
>> > dynamically generated query (www.johnmacintyre.ca). The problem is
> that
>> > I am trying to pivot biological taxonomy information, and may end
> up
>> > with a table containing over 200 columns. This takes the dynamic
> string
>> > well over the 8000char limit for variables.
>>> >>From my understanding, the EXEC() command does not have the
> 8000char
>> > limit if the execution string is broken into chunks, and
> concatenated
>> > e.g. EXEC(sql1 + sql2 + sql3 + ...). So the solution I think I need
> is
>> > to:
>>> > 1) start a counter at the beginining of the dynamic generation
>> > 2) append the counter value to the end of a string variable name
>> > 3) DECLARE the new variable and attach that loop cycle of text to
> it,
>> > or attach each chunk of characters < 8000
>> > 4) build the EXEC() string by concatenating each dynamic varible
>>> > Can this be done? Should it be done? Is there a better way to
> address
>> > this type of problem?
>>> > Thanks for any ideas or insights
>>> > Tim Pascoe
>|||(tim.pascoe@.cciw.ca) writes:
> I'm attempting to modify some Crosstab generating code, and I need some
> advice/examples.
> Currently, the code uses a single string variable to store the
> dynamically generated query (www.johnmacintyre.ca). The problem is that
> I am trying to pivot biological taxonomy information, and may end up
> with a table containing over 200 columns. This takes the dynamic string
> well over the 8000char limit for variables.
>>From my understanding, the EXEC() command does not have the 8000char
> limit if the execution string is broken into chunks, and concatenated
> e.g. EXEC(sql1 + sql2 + sql3 + ...). So the solution I think I need is
> to:
> 1) start a counter at the beginining of the dynamic generation
> 2) append the counter value to the end of a string variable name
> 3) DECLARE the new variable and attach that loop cycle of text to it,
> or attach each chunk of characters < 8000
> 4) build the EXEC() string by concatenating each dynamic varible
> Can this be done? Should it be done? Is there a better way to address
> this type of problem?

I think it can be done, but I would not like to do it. You would have
to generate dynamic SQL which in its turn generates the dynamic SQL
that executes the query.

It may be a better alternative to use a client language to generate the
SQL. If you use a language like Perl or Visual Basic which has unlimited
strings, you are saved the restriction of varchar(8000). Note that all
that you would bring to the client would be the meta data needed to
form the SQL statement.

In SQL 2005 there is a new data type varchar(MAX) which is akin to text,
but works more like varchar, and thus in SQL 2005 you would also be saved
from the varchar(8000) restriction. SQL 2005 is currently in beta, with
release planned next year.
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

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

Friday, February 24, 2012

debugging SPs in vs.net

[sorry but my first post got a "non-answer" so I am reposting]
I have followed examples in a couple of books but am still unable to step
into Stored Procedures in VS.NET.
I enable sql debugging in the project properties, open the sp in server
explorer and highlight a line where I want to start stepping through, then I
select a line in my VB code such as cmd.ExecuteNonQuery().
But vs.net does not step into the SP it just steps over the
cmd.ExecuteNonQuery() even though I am clicking on the Step Into icon on the
toolbar (F8 doesn't work on my computer)
Am I missing something?
Thanks,
GG Dean Blake wrote:
> [sorry but my first post got a "non-answer" so I am reposting]
> I have followed examples in a couple of books but am still unable to
> step into Stored Procedures in VS.NET.
> I enable sql debugging in the project properties, open the sp in
> server explorer and highlight a line where I want to start stepping
> through, then I select a line in my VB code such as
> cmd.ExecuteNonQuery().
> But vs.net does not step into the SP it just steps over the
> cmd.ExecuteNonQuery() even though I am clicking on the Step Into icon
> on the toolbar (F8 doesn't work on my computer)
>
Have you browsed through the other questions in this newsgroup? Have you
seen any questions dealing with vs.net? Maybe that should be an indication
that you've asked in the wrong place.
There are several newsgroups (communities) set up for the .Net framework -
they all have the word "dotnet" in their names. The one you want probably
has both "vsnet" and "debug" or "debugging" in its name. I don't have time
to find it right now, but I think you have enough clues now to find it
yourself ... :-)
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.|||Well, the two answers I have gotten in other groups (.net groups) were that
it doesn't work but everyone seems pretty closed mouth about it. Since
practical alternatives might be to use another tool, I though I would try
this group since (1) a lot of people here probably debug stored procedures,
and (23) most MS oriented developers use .net anyway.
but, I am very sorry for asking here.
G
"Bob Barrows [MVP]" <reb01501@.NOyahoo.SPAMcom> wrote in message
news:OCyHmTiCFHA.520@.TK2MSFTNGP09.phx.gbl...
>G Dean Blake wrote:
> Have you browsed through the other questions in this newsgroup? Have you
> seen any questions dealing with vs.net? Maybe that should be an indication
> that you've asked in the wrong place.
> There are several newsgroups (communities) set up for the .Net framework -
> they all have the word "dotnet" in their names. The one you want probably
> has both "vsnet" and "debug" or "debugging" in its name. I don't have time
> to find it right now, but I think you have enough clues now to find it
> yourself ... :-)
> Bob Barrows
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>|||G Dean Blake wrote:
> Well, the two answers I have gotten in other groups (.net groups)
> were that it doesn't work but everyone seems pretty closed mouth
> about it. Since practical alternatives might be to use another tool,
> I though I would try this group since (1) a lot of people here
> probably debug stored procedures,
This is true. But most people in this group generally concentrate on using
SQL Query Analyzer for this. My suggestion is to try and get debugging
working in Query Analyzer. This seems to be a prerequisite for getting it to
work in vs.net, at least in my experience.

> and (23) most MS oriented
> developers use .net anyway.
This is not true. .Net is still relatively new.

> but, I am very sorry for asking here.
> G
Oops, you're apologizing. I did not intend to make you feel as if you had to
apologize. I was trying to explain why you weren't getting help here. I
worded my reply badly so I apologize. (kumbaya ... ) <grin>
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Tuesday, February 14, 2012

debbuging SPs in VS.NET

I have followed examples in a couple of books but am still unable to step
into Stored Procedures in VS.NET.
I enable sql debugging in the project properties, open the sp in server
explorer and highlight a line where I want to start stepping through, then I
select a line in my VB code such as cmd.ExecuteNonQuery().
But vs.net does not step into the SP it just steps over the
cmd.ExecuteNonQuery() even though I am clicking on the Step Into icon on the
toolbar (F8 doesn't work on my computer)
Am I missing something?
Thanks,
GAnswered in .NET groups
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"G Dean Blake" wrote:

> I have followed examples in a couple of books but am still unable to step
> into Stored Procedures in VS.NET.
> I enable sql debugging in the project properties, open the sp in server
> explorer and highlight a line where I want to start stepping through, then
I
> select a line in my VB code such as cmd.ExecuteNonQuery().
> But vs.net does not step into the SP it just steps over the
> cmd.ExecuteNonQuery() even though I am clicking on the Step Into icon on t
he
> toolbar (F8 doesn't work on my computer)
> Am I missing something?
> Thanks,
> G
>
>