Showing posts with label writing. Show all posts
Showing posts with label writing. Show all posts

Monday, March 26, 2012

Parentheses in SQL Server 2005 Management Studio

When writing queries in the query editor of SQL Server 2005 Management Studio, I would like the matching parentheses to be highlighted whenever I have my cursor over an opening parentheses. Obviously this functionality is there. If you delete and retype and existing opening parentheses, the matching closing paren will be highlighted. How do I turn this on all the time? Thanks,

Hi Brian, Sounds like this is a possible bug. Check out the product feedback center you can search to see if someone else has submitted the same problem, if so you can vote on it, if not you can submit it. You can access the product feedback center by going to http://lab.msdn.microsoft.com/productfeedback/Default.aspx.

Cheers,
Dan

|||I filed a bug report that can be found at:
http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=175f05ad-830d-4070-bc4e-1c9a4ee23ad4

Parent/child SQL query

Hello, I woud like to find a resource (book, web site, etc.) that
demonstrates writing queries related to parent/child relationships. In
particular I have a table that contains an unknown number of parents/childre
n
(and grand-children, great grand children, etc). I would like to create a
pivot table so that all the parents become columns and each row represents a
child (grand child, great grand child, etc.) for that parent.
Thank you,
RicOne of them is "Trees and Hierarchies" by Joe Celko. I'm sure he's just
writing a response himself. ;)
However, what you've specified in your post is best handled on the client,
as it's obviously just for presentation purposes (it breaks nromalization).
ML
http://milambda.blogspot.com/|||>> I woud like to find a resource (book, web site, etc.) that demonstrates w
riting queries related to parent/child relationships.<<
Buy a copies of TREES & HIERARCHIES IN SQL, of course! Steral the code
in the book.|||Check out the stuff Izik Ben Gan has done on trees and hierarchies.
Don't buy celko's book, its based around standard sql rather than Microsoft
SQL Server so you'll find it hard to implement, also, a lot of his methods
are slow, dont scale and out of date.
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"Ric" <Ric@.discussions.microsoft.com> wrote in message
news:CB71D7E5-0534-404B-8787-1F2F527F0D0A@.microsoft.com...
> Hello, I woud like to find a resource (book, web site, etc.) that
> demonstrates writing queries related to parent/child relationships. In
> particular I have a table that contains an unknown number of
> parents/children
> (and grand-children, great grand children, etc). I would like to create a
> pivot table so that all the parents become columns and each row represents
> a
> child (grand child, great grand child, etc.) for that parent.
> Thank you,
> Ric|||"Tony Rogerson" <tonyrogerson@.sqlserverfaq.com> wrote in message
news:OEbv0ykIGHA.3896@.TK2MSFTNGP15.phx.gbl...
> Check out the stuff Izik Ben Gan has done on trees and hierarchies.
Yes, but why isn't there dedicated sql for this?
Even if they had to use xml? :)
I know, it's a high priority for a future release......Please:):(

> Don't buy celko's book, its based around standard sql rather than
> Microsoft SQL Server so you'll find it hard to implement, also, a lot of
> his methods are slow, dont scale and out of date.
Yes, but why is it so popular on this ng?
Required reading according to many of the experts!
The twilight is blinding...:)
www.rac4sql.net|||>> Yes, but why isn't there dedicated sql for this? Even if they had to use
xml? :) <<
Recursive CTE expressions are now a part of Standard SQL. I like CTEs
but I do not like the recursirve version -- it seldom used so it
destorts the engine and it is a screaming XXXXX to optimize.
You silly boy! Because this book is the brilliant work of a known SQL
genius, who is kind to animals, God's gift to strippers as well as
undergrad math students, and so much nicer in person than on
Newsgroups!! Soon to be listed on a webite for sainthood ..
Seriously, if you cannot translate Standard SQL into any product
dialect, then you are a truly bad SQL programmer. This is like saying
"I only speak Hillbilly English and cannot leave my ghetto!"
"Caesar: Pardon him, Theodotus. He is a barbarian and thinks the
customs of his tribe and island are the laws of nature." - Caesar and
Cleopatra; George Bernard Shaw 1898|||> ...God's gift to strippers as well as
> undergrad math students...
Geez! LOL :)

> Soon to be listed on a webite for sainthood...
Be sure to post the link. ;)
ML
http://milambda.blogspot.com/|||>> > Soon to be listed on a website for sainthood...Be sure to post the link
. ;) <<
Well, first, I have to get the domain registered ...

Monday, March 12, 2012

Parameters passed to Stored Procedure from ASP

I'm relatively new to stored procedure writing. My situation is an ASP page allowing multiple selections from a <select> option passing 1 to x number of options to a stored proc. for the WHERE clause.
For instance, a user selects 1,3,5 and 6. These would need to be passed to the sp and then:

...FROM [tablename]
WHERE (Number = @.param1) OR (Number = @.param2) OR (Number = @.param3) OR (Number = @.param4) etc...

This sp ties into a Crystal Report and in the above scenario, should return data for colums equal to 1 3 5 and 6. If only 1 and 6 had been selected on the ASP page, then only those two would be assigned a value in the sp.

Any suggestions?
Thanks in advance...

IIS 5.0, Win 2k, MSSQL 7.0Just create an ado connection/command objects and execute the stored procedure. What are the ranges for the parameters ?|||Looks like you want to say something like

WHERE col1 IN (@.param1, @.param2, @.param3, @.param4)

Or

WHERE col1 IN (@.param1, @.param2)

whatever the case may be...is that right?

Or are they diferent columns|||Well, if the ASP was passing three different parameters (Start Date, End Date, Details) they would be passed to the sp like(whereas the strStartDate, strEndDate and strDetails were assigned the Request.Form values):

Set ThisParam = StoredProcParamCollection.item(1)
ThisParam.SetCurrentValue cstr(strStartDate), 12

Set ThisParam = StoredProcParamCollection.item(2)
ThisParam.SetCurrentValue cstr(strEndDate), 12

Set ThisParam = StoredProcParamCollection.item(3)
ThisParam.SetCurrentValue cstr(strDetails), 12

However, in my scenario, I need to allow for multiple selections in one Request.Form("select") collection so to speak passed to the sp.

Does that make sense??
:-\|||What is the maximum number of selections in the select box - and will this keep growing ?|||The select box as 12 selections. The user can pick as few as one or as many as all. Basically, any combination. Say they pick 1 & 2. I need to pass those selections to the sp and use those parameters in the where

WHERE [columnname] = @.parameter1 or [columnname] = @.parameter2 or [columnname] = @.parameter3(parameter 3 remains default value since only 1 and two were passed in)

(The parameters are assign the passed values or remain default if no value passed)|||How come you don't ask for a variable result set from the SELECT..can't they pick their own fields too?

Don't want to use the D word....

Have you run a sql statement with all 13 parameters?

Can we see the sproc...

Is it like CREATE PROC mySproc @.Param1 = null, @.Param2 = null

Maybe you can pass all of them

and do WHERE Col1 = ISNULL(@.Param1,Col1) AND...|||You could set up one parameter and pass a delimited string containing all your selections.

You then split the string up and use the in statement to do your selection.

It's not pretty but it will work.

Let me know if you want details of how to do this.|||Brett & rokslide, thanks for the help. Basically, the options aren't added from a db connection into the asp page. So, hard coding the 12 values (which never change as they are campus locations) isn't a problem. So, the intent was to pass any combination of selected campuses, pass them to a sp and generate a report for the campuses selected.

...FROM [tablename]
WHERE (Number = @.param1) OR (Number = @.param2) OR (Number = @.param3) OR (Number = @.param4) etc...

Is basically what I need to do, but I like the delimited idea and splitting the string and doing the select through iteration.

Friday, March 9, 2012

parameters in stored procedure...

Hello,
I am writing a stored procedure and noticed for a
particular stored procedure there is a pattern that I
would consider writing a template class for. In
particular the names of the tables, the name of field for
the table that I am checking for and the name of data..
( I don't know if my table design is good or not... but I
figured that if the names were all the same I should be
able to get some code reuse somewhere... )
Anyway the question I have: Is there a way that I can
capitolize on the fact that the fields have the same names
in the tables?
for example: (very rough pseudo code )
exec AddData( "City", @.Name )
exec AddData( "State", @.Name
Where "City" and "State" are table names
and @.Name is the name of the city/state that I am
interested in adding to the DB:
Here is what I am currently doing:
ie:
if exists( select City.[Index] from City where City.Name = @.CityName )
begin
select @.IndexCity = City.[Index] from City where City.Name
= @.CityName
end
else
begin
set @.IndexCity = newid()
insert into City( City.[Index], Name) values( @.IndexCity,
@.CityName )
end
if exists( select State.[Index] from State where
State.Name = @.StateName )
begin
select @.IndexState = State.[Index] from State where
State.Name = @.StateName
end
else
begin
set @.IndexState = newid()
insert into State( State.[Index], Name) values(
@.IndexState, @.StateName )
end
Thanks
MeYou would have to use dynamic SQL, which has a lot of drawbacks. See:
http://www.sommarskog.se/dynamic_sql.html
--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as_ugroup=microsoft.public.sqlserver
"Me" <anonymous@.discussions.microsoft.com> wrote in message
news:06c301c3c45d$2f13df60$a301280a@.phx.gbl...
> Hello,
> I am writing a stored procedure and noticed for a
> particular stored procedure there is a pattern that I
> would consider writing a template class for. In
> particular the names of the tables, the name of field for
> the table that I am checking for and the name of data..
> ( I don't know if my table design is good or not... but I
> figured that if the names were all the same I should be
> able to get some code reuse somewhere... )
> Anyway the question I have: Is there a way that I can
> capitolize on the fact that the fields have the same names
> in the tables?
> for example: (very rough pseudo code )
> exec AddData( "City", @.Name )
> exec AddData( "State", @.Name
> Where "City" and "State" are table names
> and @.Name is the name of the city/state that I am
> interested in adding to the DB:
> Here is what I am currently doing:
>
> ie:
> if exists( select City.[Index] from City where City.Name => @.CityName )
> begin
> select @.IndexCity = City.[Index] from City where City.Name
> = @.CityName
> end
> else
> begin
> set @.IndexCity = newid()
> insert into City( City.[Index], Name) values( @.IndexCity,
> @.CityName )
> end
>
> if exists( select State.[Index] from State where
> State.Name = @.StateName )
> begin
> select @.IndexState = State.[Index] from State where
> State.Name = @.StateName
> end
> else
> begin
> set @.IndexState = newid()
> insert into State( State.[Index], Name) values(
> @.IndexState, @.StateName )
> end
>
> Thanks
> Me|||Thanks
>--Original Message--
>You would have to use dynamic SQL, which has a lot of
drawbacks. See:
>http://www.sommarskog.se/dynamic_sql.html
>--
>Tibor Karaszi, SQL Server MVP
>Archive at: http://groups.google.com/groups?
oi=djq&as_ugroup=microsoft.public.sqlserver
>
>"Me" <anonymous@.discussions.microsoft.com> wrote in
message
>news:06c301c3c45d$2f13df60$a301280a@.phx.gbl...
>> Hello,
>> I am writing a stored procedure and noticed for a
>> particular stored procedure there is a pattern that I
>> would consider writing a template class for. In
>> particular the names of the tables, the name of field
for
>> the table that I am checking for and the name of data..
>> ( I don't know if my table design is good or not... but
I
>> figured that if the names were all the same I should be
>> able to get some code reuse somewhere... )
>> Anyway the question I have: Is there a way that I can
>> capitolize on the fact that the fields have the same
names
>> in the tables?
>> for example: (very rough pseudo code )
>> exec AddData( "City", @.Name )
>> exec AddData( "State", @.Name
>> Where "City" and "State" are table names
>> and @.Name is the name of the city/state that I am
>> interested in adding to the DB:
>> Here is what I am currently doing:
>>
>> ie:
>> if exists( select City.[Index] from City where
City.Name =>> @.CityName )
>> begin
>> select @.IndexCity = City.[Index] from City where
City.Name
>> = @.CityName
>> end
>> else
>> begin
>> set @.IndexCity = newid()
>> insert into City( City.[Index], Name) values(
@.IndexCity,
>> @.CityName )
>> end
>>
>> if exists( select State.[Index] from State where
>> State.Name = @.StateName )
>> begin
>> select @.IndexState = State.[Index] from State where
>> State.Name = @.StateName
>> end
>> else
>> begin
>> set @.IndexState = newid()
>> insert into State( State.[Index], Name) values(
>> @.IndexState, @.StateName )
>> end
>>
>> Thanks
>> Me
>
>.
>