Showing posts with label appreciate. Show all posts
Showing posts with label appreciate. Show all posts

Monday, March 26, 2012

please help

Hi! I'm new at asp .net programming, and would appreciate a littlehelp with a problem I have. I am trying to create a social network, andthe aim of this specific VB page is to show all of the friends of theuser who is logged in. I would like to do this without using gridviews,so that I have more freedom in the way the results of the select areshown and formatted. I found some code which is perfect for anotherpage where I simply show all the users in the database. However, forthis page where I show the friends of the logged in user, I am havingdifficulties because I need to use a parameter @.Param1 which passes thevalue of the username of who is logged in. Previously I was doing thiswith gridviews, and the passing of the parameter was easy, since on thepagepreinit I could declare Session("username") = User.Identity.Nameand then simply use username inside the select command of thesqldatasource ( <asp:SessionParameter Name="Param1"SessionField="username" />)

However, now without the gridview I don't know how I can continue using this parameter. Any suggestions?
Thanks a lot!

Here is the VB code:

<%@. Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.SqlClient" %
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"
<script language="VB" runat="server">
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs)
Page.Theme = Profile.MyTheme
Session("username") = User.Identity.Name

End Sub
Sub Page_Load(Sender As Object, E As EventArgs)

Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As New SqlDataAdapter


' MyCommand.SelectCommand.Parameters.AddWithValue("@.Param1", "")
' not sure about the above line, something is missing


MyConnection = New SqlConnection("DataSource=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;IntegratedSecurity=True;User Instance=True")
MyCommand = NewSqlDataAdapter("select c.UserName from aspnet_Users a inner joinaspnet_friendship b on (a.userId = b.userId or a.userId = b.buddyId)inner join aspnet_Users c on (b.userId = c.userId or b.buddyId =c.userId) where a.UserName = @.Param1 and c.UserName <>@.Param1", MyConnection)
DS = New DataSet()
MyCommand.Fill(DS, "aspnet_Users")

MyDataList.DataSource = DS.Tables("aspnet_Users").DefaultView
MyDataList.DataBind()
End Sub

</script
<body
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox
<ASP:DataList id="MyDataList" RepeatColumns="1" runat="server"
<ItemTemplate
<table cellpadding=10 style="font: 10pt verdana">
<tr>
<td width=1 bgcolor="BD8672"/
<td valign="top">

</td
<td valign="top"
<b>Name: </b><%#DataBinder.Eval(Container.DataItem, "UserName")%><br>
<b>Photo: </b><%#DataBinder.Eval(Container.DataItem, "UserName")%><br>
<p
<a href='<%# DataBinder.Eval(Container.DataItem, "UserName", "purchase.aspx?titleid={0}") %>' >
<img border="0" src="http://pics.10026.com/?src=/quickstart/aspplus/images/purchase_book.gif" >
</a
</td>
</tr>
</table
</ItemTemplate
</ASP:DataList

</body
</asp:Content>

This should do what you are looking for

Sub Page_Load(Sender As Object, E As EventArgs)

Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter


MyConnection = New SqlConnection("DataSource=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;IntegratedSecurity=True;User Instance=True")
MyCommand = NewSqlDataAdapter("select c.UserName from aspnet_Users a inner joinaspnet_friendship b on (a.userId = b.userId or a.userId = b.buddyId)inner join aspnet_Users c on (b.userId = c.userId or b.buddyId =c.userId) where a.UserName = @.Param1 and c.UserName <>@.Param1", MyConnection)

MyCommand.SelectCommand.Parameters.AddWithValue("@.Param1", Session("username"))


DS = New DataSet()
MyCommand.Fill(DS, "aspnet_Users")

MyDataList.DataSource = DS.Tables("aspnet_Users").DefaultView
MyDataList.DataBind()
End Sub

|||

Thanks for the help. Now I get an error in the line:

MyCommand.Fill(DS, "aspnet_Users")

The error is: "The parameterized query '(@.Param1 nvarchar(4000))select c.UserName fromaspnet_Users a in' expects the parameter '@.Param1', which was notsupplied."

I am not sure what I should include inside the MyCommand.Fill in order to show the results that I want, considering what I posted before. I would like to show the friends of the logged in user.
I'm sorry I have to ask all this, but I am relatively new at this and would appreciate any help :)

Thanks.


|||

Hi!

I managed to solve the problem :)

The final code is:

<script language="VB" runat="server">
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs)
Page.Theme = Profile.MyTheme
Session("username") = User.Identity.Name
End Sub
Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)

Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter


MyConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True")

MyCommand = New SqlDataAdapter("select c.UserName from aspnet_Users a inner join aspnet_friendship b on (a.userId = b.userId or a.userId = b.buddyId) inner join aspnet_Users c on (b.userId = c.userId or b.buddyId = c.userId) where a.UserName = @.Param1 and c.UserName <> @.Param1", MyConnection)

MyCommand.SelectCommand.Parameters.AddWithValue("@.Param1", Session("username"))

DS = New DataSet()
MyCommand.Fill(DS, "aspnet_friendship")

MyDataList.DataSource = DS.Tables("aspnet_friendship").DefaultView
MyDataList.DataBind()
End Sub
</script>

Thanks once again.

Friday, March 9, 2012

PL/SQL code to load data from a flat file into a MS-SQL Server table

Hi everybody,
I am very new to MS-SQL Server and I need the PL/SQL code to load data
from a flat file into a MS-SQL Server table. I would appreciate your
kind help ASAP. Thanks in advance.> I am very new to MS-SQL Server and I need the PL/SQL code to load data
> from a flat file into a MS-SQL Server table.
PL/SQL is the term used for Oracle SQL language extensions. Transact-SQL
(often abbreviated T-SQL) is used in Microsoft/Sybase SQL Server.
You can use BULK INSERT to import data directly from a text file. See the
Books Online for usage details.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Ratan" <ratan.nitrkl@.gmail.com> wrote in message
news:1194866854.016582.213720@.e34g2000pro.googlegroups.com...
> Hi everybody,
> I am very new to MS-SQL Server and I need the PL/SQL code to load data
> from a flat file into a MS-SQL Server table. I would appreciate your
> kind help ASAP. Thanks in advance.
>|||Thank you so much Dan. Could you please suggest me some good books?
On Nov 12, 5:30 pm, "Dan Guzman" <guzma...@.nospam-
online.sbcglobal.net> wrote:
> > I am very new to MS-SQL Server and I need the PL/SQL code to load data
> > from a flat file into a MS-SQL Server table.
> PL/SQL is the term used for Oracle SQL language extensions. Transact-SQL
> (often abbreviated T-SQL) is used in Microsoft/Sybase SQL Server.
> You can use BULK INSERT to import data directly from a text file. See the
> Books Online for usage details.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Ratan" <ratan.nit...@.gmail.com> wrote in message
> news:1194866854.016582.213720@.e34g2000pro.googlegroups.com...
>
> > Hi everybody,
> > I am very new to MS-SQL Server and I need the PL/SQL code to load data
> > from a flat file into a MS-SQL Server table. I would appreciate your
> > kind help ASAP. Thanks in advance.- Hide quoted text -
> - Show quoted text -|||> Thank you so much Dan. Could you please suggest me some good books?
I suggest Inside Microsoft SQL Server 2005: T-SQL Querying
(http://www.amazon.com/Inside-Microsoft-SQL-Server-2005/dp/0735623139).
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Ratan" <ratan.nitrkl@.gmail.com> wrote in message
news:1194874763.657788.164240@.o80g2000hse.googlegroups.com...
> Thank you so much Dan. Could you please suggest me some good books?
>
> On Nov 12, 5:30 pm, "Dan Guzman" <guzma...@.nospam-
> online.sbcglobal.net> wrote:
>> > I am very new to MS-SQL Server and I need the PL/SQL code to load data
>> > from a flat file into a MS-SQL Server table.
>> PL/SQL is the term used for Oracle SQL language extensions. Transact-SQL
>> (often abbreviated T-SQL) is used in Microsoft/Sybase SQL Server.
>> You can use BULK INSERT to import data directly from a text file. See
>> the
>> Books Online for usage details.
>> --
>> Hope this helps.
>> Dan Guzman
>> SQL Server MVP
>> "Ratan" <ratan.nit...@.gmail.com> wrote in message
>> news:1194866854.016582.213720@.e34g2000pro.googlegroups.com...
>>
>> > Hi everybody,
>> > I am very new to MS-SQL Server and I need the PL/SQL code to load data
>> > from a flat file into a MS-SQL Server table. I would appreciate your
>> > kind help ASAP. Thanks in advance.- Hide quoted text -
>> - Show quoted text -
>|||Thank you so much.
On Nov 13, 9:36 am, "Dan Guzman" <guzma...@.nospam-
online.sbcglobal.net> wrote:
> > Thank you so much Dan. Could you please suggest me some good books?
> I suggest Inside Microsoft SQL Server 2005: T-SQL Querying
> (http://www.amazon.com/Inside-Microsoft-SQL-Server-2005/dp/0735623139).
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Ratan" <ratan.nit...@.gmail.com> wrote in message
> news:1194874763.657788.164240@.o80g2000hse.googlegroups.com...
>
> > Thank you so much Dan. Could you please suggest me some good books?
> > On Nov 12, 5:30 pm, "Dan Guzman" <guzma...@.nospam-
> > online.sbcglobal.net> wrote:
> >> > I am very new to MS-SQL Server and I need the PL/SQL code to load data
> >> > from a flat file into a MS-SQL Server table.
> >> PL/SQL is the term used for Oracle SQL language extensions. Transact-SQL
> >> (often abbreviated T-SQL) is used in Microsoft/Sybase SQL Server.
> >> You can use BULK INSERT to import data directly from a text file. See
> >> the
> >> Books Online for usage details.
> >> --
> >> Hope this helps.
> >> Dan Guzman
> >> SQL Server MVP
> >> "Ratan" <ratan.nit...@.gmail.com> wrote in message
> >>news:1194866854.016582.213720@.e34g2000pro.googlegroups.com...
> >> > Hi everybody,
> >> > I am very new to MS-SQL Server and I need the PL/SQL code to load data
> >> > from a flat file into a MS-SQL Server table. I would appreciate your
> >> > kind help ASAP. Thanks in advance.- Hide quoted text -
> >> - Show quoted text -- Hide quoted text -
> - Show quoted text -

PL/SQL code to load data from a flat file into a MS-SQL Server table

Hi everybody,
I am very new to MS-SQL Server and I need the PL/SQL code to load data
from a flat file into a MS-SQL Server table. I would appreciate your
kind help ASAP. Thanks in advance.> I am very new to MS-SQL Server and I need the PL/SQL code to load data
> from a flat file into a MS-SQL Server table.
PL/SQL is the term used for Oracle SQL language extensions. Transact-SQL
(often abbreviated T-SQL) is used in Microsoft/Sybase SQL Server.
You can use BULK INSERT to import data directly from a text file. See the
Books Online for usage details.
Hope this helps.
Dan Guzman
SQL Server MVP
"Ratan" <ratan.nitrkl@.gmail.com> wrote in message
news:1194866854.016582.213720@.e34g2000pro.googlegroups.com...
> Hi everybody,
> I am very new to MS-SQL Server and I need the PL/SQL code to load data
> from a flat file into a MS-SQL Server table. I would appreciate your
> kind help ASAP. Thanks in advance.
>|||Thank you so much Dan. Could you please suggest me some good books?
On Nov 12, 5:30 pm, "Dan Guzman" <guzma...@.nospam-
online.sbcglobal.net> wrote:
> PL/SQL is the term used for Oracle SQL language extensions. Transact-SQL
> (often abbreviated T-SQL) is used in Microsoft/Sybase SQL Server.
> You can use BULK INSERT to import data directly from a text file. See the
> Books Online for usage details.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Ratan" <ratan.nit...@.gmail.com> wrote in message
> news:1194866854.016582.213720@.e34g2000pro.googlegroups.com...
>
>
>
> - Show quoted text -|||> Thank you so much Dan. Could you please suggest me some good books?
I suggest Inside Microsoft SQL Server 2005: T-SQL Querying
(http://www.amazon.com/Inside-Micros...5/dp/0735623139).
Hope this helps.
Dan Guzman
SQL Server MVP
"Ratan" <ratan.nitrkl@.gmail.com> wrote in message
news:1194874763.657788.164240@.o80g2000hse.googlegroups.com...
> Thank you so much Dan. Could you please suggest me some good books?
>
> On Nov 12, 5:30 pm, "Dan Guzman" <guzma...@.nospam-
> online.sbcglobal.net> wrote:
>|||Thank you so much.
On Nov 13, 9:36 am, "Dan Guzman" <guzma...@.nospam-
online.sbcglobal.net> wrote:
> I suggest Inside Microsoft SQL Server 2005: T-SQL Querying
> (http://www.amazon.com/Inside-Micros...5/dp/0735623139).
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Ratan" <ratan.nit...@.gmail.com> wrote in message
> news:1194874763.657788.164240@.o80g2000hse.googlegroups.com...
>
>
>
>
>
>
>
>
>
>
>
>
> - Show quoted text -

PL/SQL code to load data from a flat file into a MS-SQL Server table

Hi everybody,
I am very new to MS-SQL Server and I need the PL/SQL code to load data
from a flat file into a MS-SQL Server table. I would appreciate your
kind help ASAP. Thanks in advance.
> I am very new to MS-SQL Server and I need the PL/SQL code to load data
> from a flat file into a MS-SQL Server table.
PL/SQL is the term used for Oracle SQL language extensions. Transact-SQL
(often abbreviated T-SQL) is used in Microsoft/Sybase SQL Server.
You can use BULK INSERT to import data directly from a text file. See the
Books Online for usage details.
Hope this helps.
Dan Guzman
SQL Server MVP
"Ratan" <ratan.nitrkl@.gmail.com> wrote in message
news:1194866854.016582.213720@.e34g2000pro.googlegr oups.com...
> Hi everybody,
> I am very new to MS-SQL Server and I need the PL/SQL code to load data
> from a flat file into a MS-SQL Server table. I would appreciate your
> kind help ASAP. Thanks in advance.
>
|||Thank you so much Dan. Could you please suggest me some good books?
On Nov 12, 5:30 pm, "Dan Guzman" <guzma...@.nospam-
online.sbcglobal.net> wrote:
> PL/SQL is the term used for Oracle SQL language extensions. Transact-SQL
> (often abbreviated T-SQL) is used in Microsoft/Sybase SQL Server.
> You can use BULK INSERT to import data directly from a text file. See the
> Books Online for usage details.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Ratan" <ratan.nit...@.gmail.com> wrote in message
> news:1194866854.016582.213720@.e34g2000pro.googlegr oups.com...
>
>
> - Show quoted text -
|||> Thank you so much Dan. Could you please suggest me some good books?
I suggest Inside Microsoft SQL Server 2005: T-SQL Querying
(http://www.amazon.com/Inside-Microsoft-SQL-Server-2005/dp/0735623139).
Hope this helps.
Dan Guzman
SQL Server MVP
"Ratan" <ratan.nitrkl@.gmail.com> wrote in message
news:1194874763.657788.164240@.o80g2000hse.googlegr oups.com...
> Thank you so much Dan. Could you please suggest me some good books?
>
> On Nov 12, 5:30 pm, "Dan Guzman" <guzma...@.nospam-
> online.sbcglobal.net> wrote:
>
|||Thank you so much.
On Nov 13, 9:36 am, "Dan Guzman" <guzma...@.nospam-
online.sbcglobal.net> wrote:
> I suggest Inside Microsoft SQL Server 2005: T-SQL Querying
> (http://www.amazon.com/Inside-Microsoft-SQL-Server-2005/dp/0735623139).
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Ratan" <ratan.nit...@.gmail.com> wrote in message
> news:1194874763.657788.164240@.o80g2000hse.googlegr oups.com...
>
>
>
>
>
>
>
> - Show quoted text -

Wednesday, March 7, 2012

PK Generation Or Data Synchronization - Repost

Sorry for repost, but there was a problem with my MSDN posting alias.
I would appreciate some advice on generating a PK and/or synchronizing data
between two (maybe three) locations.
Simplified scenario.
Using SQL Server 2005 (could got to 2008 if needed).
Client has two locations (central and remote).
Item record would containseven fields - six int fields (id's from component
tables) and a seventh field that would be the PK.
Most of the time the PK would be generated at central, however, should the
connection be lost, remote must be able to generate a PK also and then when
connection is restored, any new PK generated by remote must be added to
central.
The PK needs to be the same for the same combination of the six fields, no
matter which server generated it, in case both servers happened to create a
record with the same six fields. Therefore using a GUID would not work.
Since the PK will be used by another system (Great Plains), it's length is
limited to 30 characters.
I am hoping for some algorathym that would combine the six column values
and always generate the same value from the same six values. Something like
a hash code. However, I am limited to 30 characters and I do believe a hash
code is 64.
Another idea is to write routines to do the 'replication', instead of using
SQL replication.
Then add all new rows in 'remote' via a stored procedure. If the sp can't
connect to 'central' it would generate it's own PK and also record that in
another table. Then when connectivity is restored, my replication routine
would check for duplicate rows and if necessary, update the PK in 'remote'
with the PK from 'central'.
Aside from the complexity, the problem with that is I don't know if Great
Plains can use cascade update to update its' detail tables that would be
referencing my PK as an FK.
--
AG
Email: discussATadhdataDOTcomHi AG,
Appreciate your understanding that this is not a dedicated SQL Server
related question. Regarding such algorithm related consulting question, I
am afraid that we could only give you some general suggestions here. For
your requirements, I think that it is better to use cryptographic hash
function to generate PK. Though the output length is 64, you can just
retrieve the first 30 bytes. I think that the opportunity of retrieving
same PK value is also very rare. You know that GUID is just a 16 byte
value, however you are getting a 30 byte value from the hash code. You may
perform a test to insert 1 million rows to your table to see if there are
any duplicated PK values generated.
Please feel free to let me know if you have any other questions or
concerns. Have a nice day!
Best regards,
Charles Wang
Microsoft Online Community Support
===========================================================Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: msdnmg@.microsoft.com.
===========================================================Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
============================================================This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================|||Thanks for the reply Charles.
I did not expect someone to write an algorithm for me. Although if someone
already had something similar and wanted to share, that would be great.
I understand about GUID, but the problem is that, should each server
generate a new PK for the same combination of the six fields, I would want
the PK generated to be the same.
Using the hash, are you saying that it is extremely likely for the first 30
bytes to be unique and to use the million row test to confirm that?
I guess the main question here is, what do others do in similar situation? I
can't believe that this situation is so uncommon.
--
AG
Email: discussATadhdataDOTcom
"Charles Wang[MSFT]" <changliw@.online.microsoft.com> wrote in message
news:ManMJWMlIHA.3756@.TK2MSFTNGHUB02.phx.gbl...
> Hi AG,
> Appreciate your understanding that this is not a dedicated SQL Server
> related question. Regarding such algorithm related consulting question, I
> am afraid that we could only give you some general suggestions here. For
> your requirements, I think that it is better to use cryptographic hash
> function to generate PK. Though the output length is 64, you can just
> retrieve the first 30 bytes. I think that the opportunity of retrieving
> same PK value is also very rare. You know that GUID is just a 16 byte
> value, however you are getting a 30 byte value from the hash code. You may
> perform a test to insert 1 million rows to your table to see if there are
> any duplicated PK values generated.
> Please feel free to let me know if you have any other questions or
> concerns. Have a nice day!
> Best regards,
> Charles Wang
> Microsoft Online Community Support
> ===========================================================> Delighting our customers is our #1 priority. We welcome your
> comments and suggestions about how we can improve the
> support we provide to you. Please feel free to let my manager
> know what you think of the level of service provided. You can
> send feedback directly to my manager at: msdnmg@.microsoft.com.
> ===========================================================> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
> Note: The MSDN Managed Newsgroup support offering is for
> non-urgent issues where an initial response from the community
> or a Microsoft Support Engineer within 1 business day is acceptable.
> Please note that each follow up response may take approximately
> 2 business days as the support professional working with you may
> need further investigation to reach the most efficient resolution.
> The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by
> contacting Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ============================================================> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> =========================================================>|||Hi AG,
> Using the hash, are you saying that it is extremely likely for the first
30
> bytes to be unique and to use the million row test to confirm that?
Yes, I think so. You may use .NET to develop a CLR stored procedure or user
function to generate a hash code or you may use third party extended stored
procedures like this:
MD5 Hash SQL Server Extended Stored Procedure
http://www.codeproject.com/KB/database/xp_md5.aspx
Best regards,
Charles Wang
Microsoft Online Community Support
=========================================================Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: msdnmg@.microsoft.com.
=========================================================This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================|||Thanks Charles, I will give that a try.
How about responding to my last question/comment?
What do others do in similar situation?
I can't believe that this situation is so uncommon.
--
AG
Email: discussATadhdataDOTcom
"Charles Wang[MSFT]" <changliw@.online.microsoft.com> wrote in message
news:EPjgFQXlIHA.3756@.TK2MSFTNGHUB02.phx.gbl...
> Hi AG,
>> Using the hash, are you saying that it is extremely likely for the first
> 30
>> bytes to be unique and to use the million row test to confirm that?
> Yes, I think so. You may use .NET to develop a CLR stored procedure or
> user
> function to generate a hash code or you may use third party extended
> stored
> procedures like this:
> MD5 Hash SQL Server Extended Stored Procedure
> http://www.codeproject.com/KB/database/xp_md5.aspx
> Best regards,
> Charles Wang
> Microsoft Online Community Support
> =========================================================> Delighting our customers is our #1 priority. We welcome your
> comments and suggestions about how we can improve the
> support we provide to you. Please feel free to let my manager
> know what you think of the level of service provided. You can
> send feedback directly to my manager at: msdnmg@.microsoft.com.
> =========================================================> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> =========================================================>|||Hi AG,
Honestly I did not see others having such requirements before. For most
cases, you can use SQL Server replication to replicate data among different
servers. If you want high availability, you can use SQL failover cluster or
Database Mirroring? Since there is failover function on SQL Server Failover
cluster and Database Mirroring, the data consistency can be ensured on
different servers. It seems that your requirements can be fitted by using
SQL Server failover cluster or Database Mirroring (only for SQL Server 2005
or 2008).
You may refer to:
SQL Server 2005 Failover Clustering White Paper
http://www.microsoft.com/downloads/details.aspx?FamilyID=818234dc-a17b-4f09-
b282-c6830fead499&displaylang=en
Database Mirroring in SQL Server 2005
http://www.microsoft.com/technet/prodtechnol/sql/2005/dbmirror.mspx
Please feel free to let me know if you have any other questions or
concerns. Have a nice day!
Best regards,
Charles Wang
Microsoft Online Community Support
=========================================================Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: msdnmg@.microsoft.com.
=========================================================This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================|||Thanks, I will check those out.
--
AG
Email: discussATadhdataDOTcom
"Charles Wang[MSFT]" <changliw@.online.microsoft.com> wrote in message
news:qq9FvrhlIHA.7196@.TK2MSFTNGHUB02.phx.gbl...
> Hi AG,
> Honestly I did not see others having such requirements before. For most
> cases, you can use SQL Server replication to replicate data among
> different
> servers. If you want high availability, you can use SQL failover cluster
> or
> Database Mirroring? Since there is failover function on SQL Server
> Failover
> cluster and Database Mirroring, the data consistency can be ensured on
> different servers. It seems that your requirements can be fitted by using
> SQL Server failover cluster or Database Mirroring (only for SQL Server
> 2005
> or 2008).
> You may refer to:
> SQL Server 2005 Failover Clustering White Paper
> http://www.microsoft.com/downloads/details.aspx?FamilyID=818234dc-a17b-4f09-
> b282-c6830fead499&displaylang=en
> Database Mirroring in SQL Server 2005
> http://www.microsoft.com/technet/prodtechnol/sql/2005/dbmirror.mspx
> Please feel free to let me know if you have any other questions or
> concerns. Have a nice day!
> Best regards,
> Charles Wang
> Microsoft Online Community Support
> =========================================================> Delighting our customers is our #1 priority. We welcome your
> comments and suggestions about how we can improve the
> support we provide to you. Please feel free to let my manager
> know what you think of the level of service provided. You can
> send feedback directly to my manager at: msdnmg@.microsoft.com.
> =========================================================> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> =========================================================>

PK Generation Or Data Synchronization - Repost

Sorry for repost, but there was a problem with my MSDN posting alias.
I would appreciate some advice on generating a PK and/or synchronizing data
between two (maybe three) locations.
Simplified scenario.
Using SQL Server 2005 (could got to 2008 if needed).
Client has two locations (central and remote).
Item record would containseven fields - six int fields (id's from component
tables) and a seventh field that would be the PK.
Most of the time the PK would be generated at central, however, should the
connection be lost, remote must be able to generate a PK also and then when
connection is restored, any new PK generated by remote must be added to
central.
The PK needs to be the same for the same combination of the six fields, no
matter which server generated it, in case both servers happened to create a
record with the same six fields. Therefore using a GUID would not work.
Since the PK will be used by another system (Great Plains), it's length is
limited to 30 characters.
I am hoping for some algorathym that would combine the six column values
and always generate the same value from the same six values. Something like
a hash code. However, I am limited to 30 characters and I do believe a hash
code is 64.
Another idea is to write routines to do the 'replication', instead of using
SQL replication.
Then add all new rows in 'remote' via a stored procedure. If the sp can't
connect to 'central' it would generate it's own PK and also record that in
another table. Then when connectivity is restored, my replication routine
would check for duplicate rows and if necessary, update the PK in 'remote'
with the PK from 'central'.
Aside from the complexity, the problem with that is I don't know if Great
Plains can use cascade update to update its' detail tables that would be
referencing my PK as an FK.

AG
Email: discussATadhdataDOTcom
Hi AG,
Appreciate your understanding that this is not a dedicated SQL Server
related question. Regarding such algorithm related consulting question, I
am afraid that we could only give you some general suggestions here. For
your requirements, I think that it is better to use cryptographic hash
function to generate PK. Though the output length is 64, you can just
retrieve the first 30 bytes. I think that the opportunity of retrieving
same PK value is also very rare. You know that GUID is just a 16 byte
value, however you are getting a 30 byte value from the hash code. You may
perform a test to insert 1 million rows to your table to see if there are
any duplicated PK values generated.
Please feel free to let me know if you have any other questions or
concerns. Have a nice day!
Best regards,
Charles Wang
Microsoft Online Community Support
================================================== =========
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: msdnmg@.microsoft.com.
================================================== =========
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
================================================== ==========
This posting is provided "AS IS" with no warranties, and confers no rights.
================================================== =======
|||Thanks for the reply Charles.
I did not expect someone to write an algorithm for me. Although if someone
already had something similar and wanted to share, that would be great.
I understand about GUID, but the problem is that, should each server
generate a new PK for the same combination of the six fields, I would want
the PK generated to be the same.
Using the hash, are you saying that it is extremely likely for the first 30
bytes to be unique and to use the million row test to confirm that?
I guess the main question here is, what do others do in similar situation? I
can't believe that this situation is so uncommon.
AG
Email: discussATadhdataDOTcom
"Charles Wang[MSFT]" <changliw@.online.microsoft.com> wrote in message
news:ManMJWMlIHA.3756@.TK2MSFTNGHUB02.phx.gbl...
> Hi AG,
> Appreciate your understanding that this is not a dedicated SQL Server
> related question. Regarding such algorithm related consulting question, I
> am afraid that we could only give you some general suggestions here. For
> your requirements, I think that it is better to use cryptographic hash
> function to generate PK. Though the output length is 64, you can just
> retrieve the first 30 bytes. I think that the opportunity of retrieving
> same PK value is also very rare. You know that GUID is just a 16 byte
> value, however you are getting a 30 byte value from the hash code. You may
> perform a test to insert 1 million rows to your table to see if there are
> any duplicated PK values generated.
> Please feel free to let me know if you have any other questions or
> concerns. Have a nice day!
> Best regards,
> Charles Wang
> Microsoft Online Community Support
> ================================================== =========
> Delighting our customers is our #1 priority. We welcome your
> comments and suggestions about how we can improve the
> support we provide to you. Please feel free to let my manager
> know what you think of the level of service provided. You can
> send feedback directly to my manager at: msdnmg@.microsoft.com.
> ================================================== =========
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
> Note: The MSDN Managed Newsgroup support offering is for
> non-urgent issues where an initial response from the community
> or a Microsoft Support Engineer within 1 business day is acceptable.
> Please note that each follow up response may take approximately
> 2 business days as the support professional working with you may
> need further investigation to reach the most efficient resolution.
> The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by
> contacting Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ================================================== ==========
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> ================================================== =======
>
|||Hi AG,
> Using the hash, are you saying that it is extremely likely for the first
30
> bytes to be unique and to use the million row test to confirm that?
Yes, I think so. You may use .NET to develop a CLR stored procedure or user
function to generate a hash code or you may use third party extended stored
procedures like this:
MD5 Hash SQL Server Extended Stored Procedure
http://www.codeproject.com/KB/database/xp_md5.aspx
Best regards,
Charles Wang
Microsoft Online Community Support
================================================== =======
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: msdnmg@.microsoft.com.
================================================== =======
This posting is provided "AS IS" with no warranties, and confers no rights.
================================================== =======
|||Thanks Charles, I will give that a try.
How about responding to my last question/comment?
What do others do in similar situation?
I can't believe that this situation is so uncommon.
AG
Email: discussATadhdataDOTcom
"Charles Wang[MSFT]" <changliw@.online.microsoft.com> wrote in message
news:EPjgFQXlIHA.3756@.TK2MSFTNGHUB02.phx.gbl...
> Hi AG,
> 30
> Yes, I think so. You may use .NET to develop a CLR stored procedure or
> user
> function to generate a hash code or you may use third party extended
> stored
> procedures like this:
> MD5 Hash SQL Server Extended Stored Procedure
> http://www.codeproject.com/KB/database/xp_md5.aspx
> Best regards,
> Charles Wang
> Microsoft Online Community Support
> ================================================== =======
> Delighting our customers is our #1 priority. We welcome your
> comments and suggestions about how we can improve the
> support we provide to you. Please feel free to let my manager
> know what you think of the level of service provided. You can
> send feedback directly to my manager at: msdnmg@.microsoft.com.
> ================================================== =======
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> ================================================== =======
>
|||Hi AG,
Honestly I did not see others having such requirements before. For most
cases, you can use SQL Server replication to replicate data among different
servers. If you want high availability, you can use SQL failover cluster or
Database Mirroring? Since there is failover function on SQL Server Failover
cluster and Database Mirroring, the data consistency can be ensured on
different servers. It seems that your requirements can be fitted by using
SQL Server failover cluster or Database Mirroring (only for SQL Server 2005
or 2008).
You may refer to:
SQL Server 2005 Failover Clustering White Paper
http://www.microsoft.com/downloads/details.aspx?FamilyID=818234dc-a17b-4f09-
b282-c6830fead499&displaylang=en
Database Mirroring in SQL Server 2005
http://www.microsoft.com/technet/prodtechnol/sql/2005/dbmirror.mspx
Please feel free to let me know if you have any other questions or
concerns. Have a nice day!
Best regards,
Charles Wang
Microsoft Online Community Support
================================================== =======
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: msdnmg@.microsoft.com.
================================================== =======
This posting is provided "AS IS" with no warranties, and confers no rights.
================================================== =======
|||Thanks, I will check those out.
AG
Email: discussATadhdataDOTcom
"Charles Wang[MSFT]" <changliw@.online.microsoft.com> wrote in message
news:qq9FvrhlIHA.7196@.TK2MSFTNGHUB02.phx.gbl...
> Hi AG,
> Honestly I did not see others having such requirements before. For most
> cases, you can use SQL Server replication to replicate data among
> different
> servers. If you want high availability, you can use SQL failover cluster
> or
> Database Mirroring? Since there is failover function on SQL Server
> Failover
> cluster and Database Mirroring, the data consistency can be ensured on
> different servers. It seems that your requirements can be fitted by using
> SQL Server failover cluster or Database Mirroring (only for SQL Server
> 2005
> or 2008).
> You may refer to:
> SQL Server 2005 Failover Clustering White Paper
> http://www.microsoft.com/downloads/details.aspx?FamilyID=818234dc-a17b-4f09-
> b282-c6830fead499&displaylang=en
> Database Mirroring in SQL Server 2005
> http://www.microsoft.com/technet/prodtechnol/sql/2005/dbmirror.mspx
> Please feel free to let me know if you have any other questions or
> concerns. Have a nice day!
> Best regards,
> Charles Wang
> Microsoft Online Community Support
> ================================================== =======
> Delighting our customers is our #1 priority. We welcome your
> comments and suggestions about how we can improve the
> support we provide to you. Please feel free to let my manager
> know what you think of the level of service provided. You can
> send feedback directly to my manager at: msdnmg@.microsoft.com.
> ================================================== =======
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> ================================================== =======
>

PK Generation Or Data Synchronization

I would appreciate some advice on generating a PK and/or synchronizing data
between two (maybe three) locations.
Simplified scenario.
Using SQL Server 2005 (could got to 2008 if needed).
Client has two locations (central and remote).
Item record would containseven fields - six int fields (id's from component
tables) and a seventh field that would be the PK.
Most of the time the PK would be generated at central, however, should the
connection be lost, remote must be able to generate a PK also and then when
connection is restored, any new PK generated by remote must be added to
central.
The PK needs to be the same for the same combination of the six fields, no
matter which server generated it, in case both servers happened to create a
record with the same six fields. Therefore using a GUID would not work.
Since the PK will be used by another system (Great Plains), it's length is
limited to 30 characters.
AG
Email: discussATadhdataDOTcom
Well you could simply use a coded IDENTITY or similar. By coded, I mean
generating the new ID in a central table, and on each server the identity
seed is different, e.g. on central it starts at 1, on remote it starts at
something like 2000000 or some reasonably large number that you won't get to
in central. INTs are big and BIGINTs are bigger; for the latter you could
spread the numbers out over a million servers and still have plenty of room
to grow for just about any business model. In addition to ensuring
uniqueness, this way when you replicate data back to central, you know which
rows were created on the remote system (which a GUID wouldn't tell you).
However, now that I mention GUID, I am thinking about one of your final
comments. If the systems cannot talk to each other, and regardless of what
methodology you use for your surrogate key, what are you going to do to
consolidate when the remote server creates a new row where the six columns
are the same as a row that already exists in the central database? (Even if
you are using replication, let's say that row was created just before the
server went down, and the row was never copied to remote.) You can't
prevent the new row from being inserted, because you don't know such a row
already exists!
"AG" <NOSPAMa-giam@.newsgroups.nospam> wrote in message
news:uxVTMTHkIHA.5724@.TK2MSFTNGP03.phx.gbl...
>I would appreciate some advice on generating a PK and/or synchronizing data
>between two (maybe three) locations.
> Simplified scenario.
> Using SQL Server 2005 (could got to 2008 if needed).
> Client has two locations (central and remote).
> Item record would containseven fields - six int fields (id's from
> component tables) and a seventh field that would be the PK.
> Most of the time the PK would be generated at central, however, should the
> connection be lost, remote must be able to generate a PK also and then
> when connection is restored, any new PK generated by remote must be added
> to central.
> The PK needs to be the same for the same combination of the six fields, no
> matter which server generated it, in case both servers happened to create
> a record with the same six fields. Therefore using a GUID would not work.
> Since the PK will be used by another system (Great Plains), it's length is
> limited to 30 characters.
> --
> AG
> Email: discussATadhdataDOTcom
>
|||Thanks for the quick reply Aaron.
I had thought about a GUID also. As well as generating the PK in a trigger
using odd numbers for one server and even for another, but your idea of a
different identity seed is simpler and more scalable.
However, as you stated also, the problem is that there could be the same six
columns with different PK's generated by both servers when connection is
down.
I was hoping for some algorathym that would combine the six column values
and always generate the same value from the same six values. Something like
a hash code. However, I am limited to 30 characters and I do believe a hash
code is 64.
Another idea is to write routines to do the 'replication', instead of using
SQL replication.
Then add all new rows in 'remote' via a stored procedure. If the sp can't
connect to 'central' it would generate it's own PK and also record that in
another table. Then when connectivity is restored, my replication routine
would check for duplicate rows and if necessary, update the PK in 'remote'
with the PK from 'central'.
Aside from the complexity, the problem with that is I don't know if Great
Plains can use cascade update to update its' detail tables that would be
referencing my PK as an FK.
AG
Email: discussATadhdataDOTcom
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:2BD5421B-65B2-4B86-8080-015FC8A50740@.microsoft.com...
> Well you could simply use a coded IDENTITY or similar. By coded, I mean
> generating the new ID in a central table, and on each server the identity
> seed is different, e.g. on central it starts at 1, on remote it starts at
> something like 2000000 or some reasonably large number that you won't get
> to in central. INTs are big and BIGINTs are bigger; for the latter you
> could spread the numbers out over a million servers and still have plenty
> of room to grow for just about any business model. In addition to
> ensuring uniqueness, this way when you replicate data back to central, you
> know which rows were created on the remote system (which a GUID wouldn't
> tell you).
> However, now that I mention GUID, I am thinking about one of your final
> comments. If the systems cannot talk to each other, and regardless of
> what methodology you use for your surrogate key, what are you going to do
> to consolidate when the remote server creates a new row where the six
> columns are the same as a row that already exists in the central database?
> (Even if you are using replication, let's say that row was created just
> before the server went down, and the row was never copied to remote.) You
> can't prevent the new row from being inserted, because you don't know such
> a row already exists!
>
>
> "AG" <NOSPAMa-giam@.newsgroups.nospam> wrote in message
> news:uxVTMTHkIHA.5724@.TK2MSFTNGP03.phx.gbl...
>

PK Generation Or Data Synchronization

I would appreciate some advice on generating a PK and/or synchronizing data
between two (maybe three) locations.
Simplified scenario.
Using SQL Server 2005 (could got to 2008 if needed).
Client has two locations (central and remote).
Item record would containseven fields - six int fields (id's from component
tables) and a seventh field that would be the PK.
Most of the time the PK would be generated at central, however, should the
connection be lost, remote must be able to generate a PK also and then when
connection is restored, any new PK generated by remote must be added to
central.
The PK needs to be the same for the same combination of the six fields, no
matter which server generated it, in case both servers happened to create a
record with the same six fields. Therefore using a GUID would not work.
Since the PK will be used by another system (Great Plains), it's length is
limited to 30 characters.
--
AG
Email: discussATadhdataDOTcomWell you could simply use a coded IDENTITY or similar. By coded, I mean
generating the new ID in a central table, and on each server the identity
seed is different, e.g. on central it starts at 1, on remote it starts at
something like 2000000 or some reasonably large number that you won't get to
in central. INTs are big and BIGINTs are bigger; for the latter you could
spread the numbers out over a million servers and still have plenty of room
to grow for just about any business model. In addition to ensuring
uniqueness, this way when you replicate data back to central, you know which
rows were created on the remote system (which a GUID wouldn't tell you).
However, now that I mention GUID, I am thinking about one of your final
comments. If the systems cannot talk to each other, and regardless of what
methodology you use for your surrogate key, what are you going to do to
consolidate when the remote server creates a new row where the six columns
are the same as a row that already exists in the central database? (Even if
you are using replication, let's say that row was created just before the
server went down, and the row was never copied to remote.) You can't
prevent the new row from being inserted, because you don't know such a row
already exists!
"AG" <NOSPAMa-giam@.newsgroups.nospam> wrote in message
news:uxVTMTHkIHA.5724@.TK2MSFTNGP03.phx.gbl...
>I would appreciate some advice on generating a PK and/or synchronizing data
>between two (maybe three) locations.
> Simplified scenario.
> Using SQL Server 2005 (could got to 2008 if needed).
> Client has two locations (central and remote).
> Item record would containseven fields - six int fields (id's from
> component tables) and a seventh field that would be the PK.
> Most of the time the PK would be generated at central, however, should the
> connection be lost, remote must be able to generate a PK also and then
> when connection is restored, any new PK generated by remote must be added
> to central.
> The PK needs to be the same for the same combination of the six fields, no
> matter which server generated it, in case both servers happened to create
> a record with the same six fields. Therefore using a GUID would not work.
> Since the PK will be used by another system (Great Plains), it's length is
> limited to 30 characters.
> --
> AG
> Email: discussATadhdataDOTcom
>|||Thanks for the quick reply Aaron.
I had thought about a GUID also. As well as generating the PK in a trigger
using odd numbers for one server and even for another, but your idea of a
different identity seed is simpler and more scalable.
However, as you stated also, the problem is that there could be the same six
columns with different PK's generated by both servers when connection is
down.
I was hoping for some algorathym that would combine the six column values
and always generate the same value from the same six values. Something like
a hash code. However, I am limited to 30 characters and I do believe a hash
code is 64.
Another idea is to write routines to do the 'replication', instead of using
SQL replication.
Then add all new rows in 'remote' via a stored procedure. If the sp can't
connect to 'central' it would generate it's own PK and also record that in
another table. Then when connectivity is restored, my replication routine
would check for duplicate rows and if necessary, update the PK in 'remote'
with the PK from 'central'.
Aside from the complexity, the problem with that is I don't know if Great
Plains can use cascade update to update its' detail tables that would be
referencing my PK as an FK.
--
AG
Email: discussATadhdataDOTcom
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:2BD5421B-65B2-4B86-8080-015FC8A50740@.microsoft.com...
> Well you could simply use a coded IDENTITY or similar. By coded, I mean
> generating the new ID in a central table, and on each server the identity
> seed is different, e.g. on central it starts at 1, on remote it starts at
> something like 2000000 or some reasonably large number that you won't get
> to in central. INTs are big and BIGINTs are bigger; for the latter you
> could spread the numbers out over a million servers and still have plenty
> of room to grow for just about any business model. In addition to
> ensuring uniqueness, this way when you replicate data back to central, you
> know which rows were created on the remote system (which a GUID wouldn't
> tell you).
> However, now that I mention GUID, I am thinking about one of your final
> comments. If the systems cannot talk to each other, and regardless of
> what methodology you use for your surrogate key, what are you going to do
> to consolidate when the remote server creates a new row where the six
> columns are the same as a row that already exists in the central database?
> (Even if you are using replication, let's say that row was created just
> before the server went down, and the row was never copied to remote.) You
> can't prevent the new row from being inserted, because you don't know such
> a row already exists!
>
>
> "AG" <NOSPAMa-giam@.newsgroups.nospam> wrote in message
> news:uxVTMTHkIHA.5724@.TK2MSFTNGP03.phx.gbl...
>>I would appreciate some advice on generating a PK and/or synchronizing
>>data between two (maybe three) locations.
>> Simplified scenario.
>> Using SQL Server 2005 (could got to 2008 if needed).
>> Client has two locations (central and remote).
>> Item record would containseven fields - six int fields (id's from
>> component tables) and a seventh field that would be the PK.
>> Most of the time the PK would be generated at central, however, should
>> the connection be lost, remote must be able to generate a PK also and
>> then when connection is restored, any new PK generated by remote must be
>> added to central.
>> The PK needs to be the same for the same combination of the six fields,
>> no matter which server generated it, in case both servers happened to
>> create a record with the same six fields. Therefore using a GUID would
>> not work.
>> Since the PK will be used by another system (Great Plains), it's length
>> is limited to 30 characters.
>> --
>> AG
>> Email: discussATadhdataDOTcom
>

Monday, February 20, 2012

pivot information

Hi there,
I haven't used queries to put data in columns in quite some time, so I'm
slightly rusty... I would appreciate some help with the following please:
(SQL 2000)
Query:
select [Date], MachNo,
case when Shift = 'A' then sum(Quantity) else 0 end as ShiftAQty,
case when Shift = 'B' then sum(Quantity) else 0 end as ShiftBQty,
case when Shift = 'C' then sum(Quantity) else 0 end as ShiftCQty
from Prod_Knitting_Data_1
group by [Date], MachNo, Shift
Result (extract):
Date Mc A B C
2008-01-07 00:00:00.000 01 0 0 400
2008-01-07 00:00:00.000 01 0 200 0
2008-01-07 00:00:00.000 02 0 0 0
2008-01-07 00:00:00.000 02 0 120 0
2008-01-07 00:00:00.000 03 0 0 180
2008-01-07 00:00:00.000 03 0 180 0
2008-01-07 00:00:00.000 03 60 0 0
As can be seen I need the results to be in one row for each date, machine
I know I'm missing something... but cannot recall what...
Thank you in advance!
Change the query to take the SUM out of the CASE function:
SELECT [Date], MachNo,
SUM(CASE WHEN Shift = 'A' THEN Quantity ELSE 0 END) AS
ShiftAQty,
SUM(CASE WHEN Shift = 'B' THEN Quantity ELSE 0 END) AS
ShiftBQty,
SUM(CASE WHEN Shift = 'C' THEN Quantity ELSE 0 END) AS ShiftCQty
FROM Prod_Knitting_Data_1
GROUP BY [Date], MachNo
HTH,
Plamen Ratchev
E-Mail: Plamen@.Ratchev.com
|||select [Date], MachNo,
sum(case when Shift = 'A' then Quantity else 0 end) as
ShiftAQty,
sum(case when Shift = 'B' then Quantity else 0 end) as
ShiftBQty,
sum(case when Shift = 'C' then Quantity else 0 end) as
ShiftCQty,
from Prod_Knitting_Data_1
group by [Date], MachNo
"PsyberFox" <PsyberFox@.discussions.microsoft.com> wrote in message
news:21D07D5F-6113-403F-8E6D-FBB4F433DEFB@.microsoft.com...
> Hi there,
> I haven't used queries to put data in columns in quite some time, so I'm
> slightly rusty... I would appreciate some help with the following please:
> (SQL 2000)
> Query:
> select [Date], MachNo,
> case when Shift = 'A' then sum(Quantity) else 0 end as
> ShiftAQty,
> case when Shift = 'B' then sum(Quantity) else 0 end as
> ShiftBQty,
> case when Shift = 'C' then sum(Quantity) else 0 end as
> ShiftCQty
> from Prod_Knitting_Data_1
> group by [Date], MachNo, Shift
>
> Result (extract):
> Date Mc A B C
> 2008-01-07 00:00:00.000 01 0 0 400
> 2008-01-07 00:00:00.000 01 0 200 0
> 2008-01-07 00:00:00.000 02 0 0 0
> 2008-01-07 00:00:00.000 02 0 120 0
> 2008-01-07 00:00:00.000 03 0 0 180
> 2008-01-07 00:00:00.000 03 0 180 0
> 2008-01-07 00:00:00.000 03 60 0 0
>
> As can be seen I need the results to be in one row for each date, machine
> I know I'm missing something... but cannot recall what...
> Thank you in advance!

pivot information

Hi there,
I haven't used queries to put data in columns in quite some time, so I'm
slightly rusty... I would appreciate some help with the following please:
(SQL 2000)
Query:
select [Date], MachNo,
case when Shift = 'A' then sum(Quantity) else 0 end as ShiftAQty,
case when Shift = 'B' then sum(Quantity) else 0 end as ShiftBQty,
case when Shift = 'C' then sum(Quantity) else 0 end as ShiftCQty
from Prod_Knitting_Data_1
group by [Date], MachNo, Shift
Result (extract):
Date Mc A B C
2008-01-07 00:00:00.000 01 0 0 400
2008-01-07 00:00:00.000 01 0 200 0
2008-01-07 00:00:00.000 02 0 0 0
2008-01-07 00:00:00.000 02 0 120 0
2008-01-07 00:00:00.000 03 0 0 180
2008-01-07 00:00:00.000 03 0 180 0
2008-01-07 00:00:00.000 03 60 0 0
As can be seen I need the results to be in one row for each date, machine
I know I'm missing something... but cannot recall what...
Thank you in advance!Change the query to take the SUM out of the CASE function:
SELECT [Date], MachNo,
SUM(CASE WHEN Shift = 'A' THEN Quantity ELSE 0 END) AS
ShiftAQty,
SUM(CASE WHEN Shift = 'B' THEN Quantity ELSE 0 END) AS
ShiftBQty,
SUM(CASE WHEN Shift = 'C' THEN Quantity ELSE 0 END) AS ShiftCQty
FROM Prod_Knitting_Data_1
GROUP BY [Date], MachNo
HTH,
Plamen Ratchev
E-Mail: Plamen@.Ratchev.com|||select [Date], MachNo,
sum(case when Shift = 'A' then Quantity else 0 end) as
ShiftAQty,
sum(case when Shift = 'B' then Quantity else 0 end) as
ShiftBQty,
sum(case when Shift = 'C' then Quantity else 0 end) as
ShiftCQty,
from Prod_Knitting_Data_1
group by [Date], MachNo
"PsyberFox" <PsyberFox@.discussions.microsoft.com> wrote in message
news:21D07D5F-6113-403F-8E6D-FBB4F433DEFB@.microsoft.com...
> Hi there,
> I haven't used queries to put data in columns in quite some time, so I'm
> slightly rusty... I would appreciate some help with the following please:
> (SQL 2000)
> Query:
> select [Date], MachNo,
> case when Shift = 'A' then sum(Quantity) else 0 end as
> ShiftAQty,
> case when Shift = 'B' then sum(Quantity) else 0 end as
> ShiftBQty,
> case when Shift = 'C' then sum(Quantity) else 0 end as
> ShiftCQty
> from Prod_Knitting_Data_1
> group by [Date], MachNo, Shift
>
> Result (extract):
> Date Mc A B C
> 2008-01-07 00:00:00.000 01 0 0 400
> 2008-01-07 00:00:00.000 01 0 200 0
> 2008-01-07 00:00:00.000 02 0 0 0
> 2008-01-07 00:00:00.000 02 0 120 0
> 2008-01-07 00:00:00.000 03 0 0 180
> 2008-01-07 00:00:00.000 03 0 180 0
> 2008-01-07 00:00:00.000 03 60 0 0
>
> As can be seen I need the results to be in one row for each date, machine
> I know I'm missing something... but cannot recall what...
> Thank you in advance!