Showing posts with label express. Show all posts
Showing posts with label express. Show all posts

Friday, February 24, 2012

GROUP BY

Hi,
I am using C# and SQL 2005 Express and I would like to know if there is a
way to group rows by some columns in such a way that I can clearly see them
in a distinguished fashion when I look at a view or table.
This is my code below but when I try using GROUP BY it is not giving me the
desired effect that I would like?
For example, let's say I would like to group by the first 5 columns (i.e.
V1,V2,V3,V4,V5) and let's say the first 3 rows of my view or table contain
the values 1,2,3,4,5 for V1,V2,V3,V4,V5 respectively, and the next 3 rows
contain the values 1,2,3,4,6 for V1,V2,V3,V4,V5 respectively and so on. What
I would like to see when I look at my view or table, is some sort of visible
delineation or break of some sort by the grouping that I chose, so that I do
not have to do it visually myself because I have many records in my view.
See my view below with the 6 rows as an example.
SELECT TOP (100) PERCENT V1, V2, V3, V4, V5, V6, V7, V8, V9, V10
FROM dbo.tblNo1
WHERE (MP <= 30)
ORDER BY V1, V2, V3, V4, V5
These are the 6 rows in my table and so as you can see the first 3 rows
would be in one group and the next 3 rows would be in another group. What I
would like to do is have to sort of way to show a distinction or highlight
between the first 3 rows and the next 3 rows.
1,2,3,4,5, 8,9,11,13,16
1,2,3,4,5, 9,11,12,15,17
1,2,3,4,5, 11,15,19,21,23
1,2,3,4,6, 8,9,12,15,18
1,2,3,4,6, 9,12,16,18,21
1,2,3,4,6, 13,16,19,20,21
Is it possible to have some kind of delineation or is what I am asking not
possible in SQL 2005 Express?
TIA
RoyThat sound rather like a crosstab query.
--
Greg Stigers, MCSA
remember to vote for the answers you like|||Hi Greg,
I think that I am getting closer as I have tried the following code below
with some success but there still remains one thing that I would like to be
able to do.
SELECT TOP (100) PERCENT V1, V2, V3, V4, V5, V6, V7, V8, V9, V10
FROM dbo.tblNo1
GROUP BY V1, V2, V3, V4, V5, V6, V7, V8, V9, V10
When I get the output from this view below I would also like to count the
number of rows that contain V1 = 1. How would I do that?
For example, if the view returns these 6 rows grouped by V1,V2,V3,V4,V5 then
I would also like to count the number of times that V1 = 1. In this case it
would be 3 because the first group 1,2,3,4,5 appears 3 times.
1,2,3,4,5, 8,9,11,13,16
1,2,3,4,5, 9,11,12,15,17
1,2,3,4,5, 11,15,19,21,23
1,2,3,4,6, 8,9,12,15,18
1,2,3,4,6, 9,12,16,18,21
1,2,3,4,6, 13,16,19,20,21
Thanks
Roy
"G" <gregstigers+msnews@.spamcop.net> wrote in message
news:%23fc7L%2319FHA.3608@.TK2MSFTNGP09.phx.gbl...
> That sound rather like a crosstab query.
> --
> Greg Stigers, MCSA
> remember to vote for the answers you like
>

GROUP BY

Hi,
I am using C# and SQL 2005 Express and I would like to know if there is a
way to group rows by some columns in such a way that I can clearly see them
in a distinguished fashion when I look at a view or table.
This is my code below but when I try using GROUP BY it is not giving me the
desired effect that I would like?
For example, let's say I would like to group by the first 5 columns (i.e.
V1,V2,V3,V4,V5) and let's say the first 3 rows of my view or table contain
the values 1,2,3,4,5 for V1,V2,V3,V4,V5 respectively, and the next 3 rows
contain the values 1,2,3,4,6 for V1,V2,V3,V4,V5 respectively and so on. What
I would like to see when I look at my view or table, is some sort of visible
delineation or break of some sort by the grouping that I chose, so that I do
not have to do it visually myself because I have many records in my view.
See my view below with the 6 rows as an example.
SELECT TOP (100) PERCENT V1, V2, V3, V4, V5, V6, V7, V8, V9, V10
FROM dbo.tblNo1
WHERE (MP <= 30)
ORDER BY V1, V2, V3, V4, V5
These are the 6 rows in my table and so as you can see the first 3 rows
would be in one group and the next 3 rows would be in another group. What I
would like to do is have to sort of way to show a distinction or highlight
between the first 3 rows and the next 3 rows.
1,2,3,4,5, 8,9,11,13,16
1,2,3,4,5, 9,11,12,15,17
1,2,3,4,5, 11,15,19,21,23
1,2,3,4,6, 8,9,12,15,18
1,2,3,4,6, 9,12,16,18,21
1,2,3,4,6, 13,16,19,20,21
Is it possible to have some kind of delineation or is what I am asking not
possible in SQL 2005 Express?
TIA
Roy
That sound rather like a crosstab query.
Greg Stigers, MCSA
remember to vote for the answers you like
|||Hi Greg,
I think that I am getting closer as I have tried the following code below
with some success but there still remains one thing that I would like to be
able to do.
SELECT TOP (100) PERCENT V1, V2, V3, V4, V5, V6, V7, V8, V9, V10
FROM dbo.tblNo1
GROUP BY V1, V2, V3, V4, V5, V6, V7, V8, V9, V10
When I get the output from this view below I would also like to count the
number of rows that contain V1 = 1. How would I do that?
For example, if the view returns these 6 rows grouped by V1,V2,V3,V4,V5 then
I would also like to count the number of times that V1 = 1. In this case it
would be 3 because the first group 1,2,3,4,5 appears 3 times.
1,2,3,4,5, 8,9,11,13,16
1,2,3,4,5, 9,11,12,15,17
1,2,3,4,5, 11,15,19,21,23
1,2,3,4,6, 8,9,12,15,18
1,2,3,4,6, 9,12,16,18,21
1,2,3,4,6, 13,16,19,20,21
Thanks
Roy
"G" <gregstigers+msnews@.spamcop.net> wrote in message
news:%23fc7L%2319FHA.3608@.TK2MSFTNGP09.phx.gbl...
> That sound rather like a crosstab query.
> --
> Greg Stigers, MCSA
> remember to vote for the answers you like
>

GROUP BY

Hi,
I am using C# and SQL 2005 Express and I would like to know if there is a
way to group rows by some columns in such a way that I can clearly see them
in a distinguished fashion when I look at a view or table.
This is my code below but when I try using GROUP BY it is not giving me the
desired effect that I would like?
For example, let's say I would like to group by the first 5 columns (i.e.
V1,V2,V3,V4,V5) and let's say the first 3 rows of my view or table contain
the values 1,2,3,4,5 for V1,V2,V3,V4,V5 respectively, and the next 3 rows
contain the values 1,2,3,4,6 for V1,V2,V3,V4,V5 respectively and so on. What
I would like to see when I look at my view or table, is some sort of visible
delineation or break of some sort by the grouping that I chose, so that I do
not have to do it visually myself because I have many records in my view.
See my view below with the 6 rows as an example.
SELECT TOP (100) PERCENT V1, V2, V3, V4, V5, V6, V7, V8, V9, V10
FROM dbo.tblNo1
WHERE (MP <= 30)
ORDER BY V1, V2, V3, V4, V5
These are the 6 rows in my table and so as you can see the first 3 rows
would be in one group and the next 3 rows would be in another group. What I
would like to do is have to sort of way to show a distinction or highlight
between the first 3 rows and the next 3 rows.
1,2,3,4,5, 8,9,11,13,16
1,2,3,4,5, 9,11,12,15,17
1,2,3,4,5, 11,15,19,21,23
1,2,3,4,6, 8,9,12,15,18
1,2,3,4,6, 9,12,16,18,21
1,2,3,4,6, 13,16,19,20,21
Is it possible to have some kind of delineation or is what I am asking not
possible in SQL 2005 Express?
TIA
RoyThat sound rather like a crosstab query.
Greg Stigers, MCSA
remember to vote for the answers you like|||Hi Greg,
I think that I am getting closer as I have tried the following code below
with some success but there still remains one thing that I would like to be
able to do.
SELECT TOP (100) PERCENT V1, V2, V3, V4, V5, V6, V7, V8, V9, V10
FROM dbo.tblNo1
GROUP BY V1, V2, V3, V4, V5, V6, V7, V8, V9, V10
When I get the output from this view below I would also like to count the
number of rows that contain V1 = 1. How would I do that?
For example, if the view returns these 6 rows grouped by V1,V2,V3,V4,V5 then
I would also like to count the number of times that V1 = 1. In this case it
would be 3 because the first group 1,2,3,4,5 appears 3 times.
1,2,3,4,5, 8,9,11,13,16
1,2,3,4,5, 9,11,12,15,17
1,2,3,4,5, 11,15,19,21,23
1,2,3,4,6, 8,9,12,15,18
1,2,3,4,6, 9,12,16,18,21
1,2,3,4,6, 13,16,19,20,21
Thanks
Roy
"G" <gregstigers+msnews@.spamcop.net> wrote in message
news:%23fc7L%2319FHA.3608@.TK2MSFTNGP09.phx.gbl...
> That sound rather like a crosstab query.
> --
> Greg Stigers, MCSA
> remember to vote for the answers you like
>

Sunday, February 19, 2012

GridView Help

Hi,

I use WVD and SQL Express 2005.

I have a table "SignIn" that one of fields inserted automatically by getdate()

And I have GridView that I use to display this table because I would like take advantage of GridView sorting and paging methods that are embedded in.

Currently I display all records at once.

My problem is how to make the GridView show today's records only.

I tried this code below, but I get only this message "There are no data records to display."

<asp:SqlDataSourceID="SqlDataSource1"runat="server"

ConnectionString="<%$ ConnectionStrings:RC1%>"

ProviderName="<%$ ConnectionStrings:RC1.ProviderName%>"

SelectCommand="SELECT [student_ID], [SignIn], [SignOut], [Location] FROM [Stud_data] WHERE (CONVERT(VARCHAR(10),[SignIn],101) = @.SignIn)">

<SelectParameters>

<asp:QueryStringParameterName="SignIn"QueryStringField="Format(Now, "M/dd/yyyy")" Type="DateTime"/>

</SelectParameters>

</asp:SqlDataSource>

Help Please!

I don't think you need use QueryStringParameter here. You can add the selectparameter from page load to assign today's date to it:

Like:

protectedvoid Page_Load(object sender,EventArgs e)

{

SqlDataSource1.SelectParameters.Add(

"SignIn",DateTime.Today.ToString("MM/dd/yyyy"));

}

}

The following is for a QueryStringParameter, but you don't need it.

SelectCommand="SELECT [student_ID], [SignIn], [SignOut], [Location] FROM [Stud_data] WHERE (CONVERT(VARCHAR(10),[SignIn],101) = @.SignIn)">

<SelectParameters>

<%

-- <asp:QueryStringParameter DefaultValue="01/01/2007" Name="SignIn" QueryStringField="mydate" Type="DateTime" />

--

%><asp:QueryStringParameterDefaultValue="1/1/2007"Name="SignIn"QueryStringField="mydate"Type="DateTime"/>

</SelectParameters>

Your URL will look something like this:

http://localhost:2013/WebSite1/queryDate.aspx?mydate=1/2/2006

|||

Thank you Limno,

SelectCommand="SELECT [student_ID], [SignIn], [SignOut], [Location] FROM [Stud_data] WHERE (CONVERT(VARCHAR(10),[SignIn],101) = @.SignIn)">

This SelectCommand solved my problem.Cool

I tried the

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)

SqlDataSource1.SelectParameters.Add("SignIn", DateTime.Today.ToString("MM/dd/yyyy"))

EndSub

And I inserted SelectParameters like this:

<asp:SqlDataSourceID="SqlDataSource1" . . .

.

.

.

<SelectParameters>

<asp:QueryStringParameterDefaultValue="1/1/2007"Name="SignIn"QueryStringField="mydate"Type="DateTime"/>

</SelectParameters>

</asp:SqlDataSource>

I keep getting the following error:

The variable name '@.SignIn' has already been declared. Variable names must be unique within a query batch or stored procedure

I wonder what I did wrong?

Thank you.

|||

alexmu06:

Thank you Limno,

SelectCommand="SELECT [student_ID], [SignIn], [SignOut], [Location] FROM [Stud_data] WHERE (CONVERT(VARCHAR(10),[SignIn],101) = @.SignIn)">

This SelectCommand solved my problem.Cool

I tried the

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)

SqlDataSource1.SelectParameters.Add("SignIn", DateTime.Today.ToString("MM/dd/yyyy"))

EndSub

And I inserted SelectParameters like this:

<asp:SqlDataSourceID="SqlDataSource1" . . .

.

.

.

<SelectParameters>

<asp:QueryStringParameterDefaultValue="1/1/2007"Name="SignIn"QueryStringField="mydate"Type="DateTime"/>

</SelectParameters>

</asp:SqlDataSource>

I keep getting the following error:

The variable name '@.SignIn' has already been declared. Variable names must be unique within a query batch or stored procedure

I wonder what I did wrong?

Thank you.

When you add the selectparameter from your code, you cannot use the declaratively again. You can use only one of them. I would prefer teh code one in your case and I hope this answers your question.

|||

Sorry but i don't get it.

if its possible could you expand a bit.

Thanks

|||

Hello:

SelectCommand="SELECT [student_ID], [SignIn], [SignOut], [Location] FROM [Stud_data] WHERE (CONVERT(VARCHAR(10),[SignIn],101) = @.SignIn)">

and the following is all you need.

ProtectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)

SqlDataSource1.SelectParameters.Add("SignIn", DateTime.Today.ToString("MM/dd/yyyy"))

EndSub

Please do not add that QueryStringParameter in your SelectParameters for this "SignIn"(you've already had it from the above code).

|||

Thank you,

I'll try that

Alex

Gridview delete behavior change from beta2 in VWD express

I've not been able to test this yet in full VS2005 (MS is screwed up with orders for some reason. Has anyone heard this one. All orders for less than quantity=5 were being rejected). So, instead of waiting for it I installed VWD Express. Now, the project had been built in VWD express beta 2, so no big change there.
Several gridview controls in the project had <Delete> enabled. Just <Delete> mind you. Nothing else for command buttons. They all worked fine with delete queries that use gridview.selectedvalue as the parameter. Every single one stopped working since I've converted from beta 2 to RTM!
Here's what I determined. The delete will only work if the row in the grid is selected first!. Otherwise <selectedvalue> is null when you click on <Delete>.
Is this a bug or what?
I'd be happy to supply more details. I am certain others will report this, but I have yet to find a post here or in any blogs out there that reproduce this problem in the RTM of .NET 2.0

On looking more closely at my earlier implementation of <Delete> I realize that the ParameterSource for the key in the grid is actually set to None in dotnet 2.0 beta 2. And it works fine. It seems to just automatically pick up the grid <datakey> value, even when that is a composite key.
My struggles to make <Delete> work again took me down the road of modifying the parameter values which is how I came to my earlier conclusion. Suffice it to say, that <Delete> in the gridview worked very automatically in beta 2. And now, no matter how much I try, the <Delete> function does not work at all.
I will keep playing with it, to see if there is some workaround other than coding things all over again to do deletes in a much more manual way.
Also, I've definitively reproduced my results by moving a working page back and forth from a .NET 2.0 beta 2 and .NET 2.0 RTM environment. Both in a development machine and W2003 server environments. As soon as I take the working page with <Delete> in the gridview from beta 2 to rtm, the <Delete> feature fails.
Anybody else that has a chance to check this out please let me know if you can reproduce this problem.

|||Hate to admit it, but I overlooked an old post here that gave me the hint I needed. Anyway, looking at delete query with SQLprofiler made it very clear. Removing the parameter for the <Delete> and changing the delete query to use the grids datakey field corrected things. Still, I have to compare this asp file to my old beta 2 file and see what happened when I copied it over and used it on the .NET 2 RTM development system. I am sure the behavior changed when I transitioned the project to the rtm version. Hope this saves others some head scatching...