显示标签为“showing”的博文。显示所有博文
显示标签为“showing”的博文。显示所有博文

2012年3月19日星期一

FK is showing PK ID instead of 'Name'

I have 2 tables, OT_ClaimantDetails and OT_OTDetails. PK in OT_OTDetails is OTDetailsID which is also FK in OT_ClaimantDetails. I am trying to run a select query to display certain data but instead of displaying the Name of the OT it displays the OTDetails ID.

SELECT OT_ClaimantDetails.ClaimantFactID, OT_ClaimantDetails.ClaimantDetailsOTDetailsID, OT_ClaimantDetails.ReferanceDIMS, OT_ClaimantDetails.DateReceived, OT_ClaimantDetails.DateEntered, OT_ClaimantDetails.DateCompleteCalc
FROM OT_ClaimantDetails, OT_OTDetails
WHERE OT_ClaimantDetails.ClaimantDetailsOTDetailsID=OT_OTDetails.OTDetailsID

How should I change my query?

Is Name a column in one of the tables? If so, which one? If not, then where does it reside?

|||No, 'Name' is the users name I'm refering to. So basically instead of showing me 'ID 5' it should show me users number 5, for example, jack. In the OT_OTdetails table I have OTDetailsID and OTName. THe OTName is the 'Name' I would like to see instead of the OTDetailsID.|||

Unless there's something I'm missing you should be able to just add it to the select list.

Code Snippet

SELECT OT_ClaimantDetails.ClaimantFactID, OT_ClaimantDetails.ClaimantDetailsOTDetailsID, OT_ClaimantDetails.ReferanceDIMS, OT_ClaimantDetails.DateReceived, OT_ClaimantDetails.DateEntered, OT_ClaimantDetails.DateCompleteCalc, OT_OTDetails.OTName

|||tried it, doesn't work. What I have done, I have changed the FK (used to be OT_ClaimantDetails.OTDetailsID) to OT_ClaimantDetails.ClaimantDetailsOTDetailsID, because I received a "Ambiguous column name" error in my browser. This solved the problem to display my results again, but now I see OTDetailsID instead of the OTName.|||

Can you post your DDL?

I don't see where you're referencing any OT_OTDetails columns in your select.

This doesn't make sense.

|||

I'm new at this, what do you mean by "post DDL"?

Wouldn't the referance to the Foreign Key, "OT_ClaimantDetails.ClaimantDetailsOTDetailsID", get the data from the OT_OTDetails column?|||

DDL = Data Definition Language....your table definitions.

>>Wouldn't the referance to the Foreign Key, "OT_ClaimantDetails.ClaimantDetailsOTDetailsID", get the data from the OT_OTDetails column?

No.

But you are joining the two tables together on the OTDetailsID (in your where clause).

So columns from the OT_OTDetail should be available.


When you put OTName in the select list, do you qualify it with OT_OTDetails. (not OT_ClaimantDetails)?

|||

It would help us better assist you if you could include table DDL, query strategy used so far, sample data in the form of INSERT statements, and an illustration of the desired results. (For help with that refer to: http://www.aspfaq.com/5006 and to http://classicasp.aspfaq.com/general/how-do-i-make-sure-my-asp-question-gets-answered.html )

The less 'set up' work we have to do, the more likely you are going to have folks tackle your problem and help you. Without this effort from you, we are just playing guessing games.

|||Standby guys, I'm going to try and get the DDL posted, maybe this will help you to help me.|||

I'm using SQL 2005.

Column OT_ClaimantDetails

USE [jwest_absolutedi]

GO

/****** Object: Table [dbo].[OT_ClaimantDetails] Script Date: 05/31/2007 17:07:41 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

SET ANSI_PADDING ON

GO

CREATE TABLE [dbo].[OT_ClaimantDetails](

[ClaimantDetailsID] [int] IDENTITY(1,1) NOT NULL,

[ReferanceDIMS] [varchar](50) NULL,

[ReferanceClient] [varchar](50) NULL,

[DateReceived] [datetime] NULL,

[DateEntered] [datetime] NULL,

[DateContactClaimant] [datetime] NULL,

[DateContactClient] [datetime] NULL,

[DateAppointm] [datetime] NULL,

[DateComplExpect] [datetime] NULL,

[DateCompleteActual] [datetime] NULL,

[DateCompleteCalc] [nchar](10) NULL,

[ReportOT] [varchar](250) NULL,

[ReportClient] [varchar](250) NULL,

[ClaimantFactID] [int] NULL,

[CompanyDetailsID] [int] NULL,

[ClaimantDetailsOTDetailsID] [int] NULL,

[BenefitsID] [int] NULL,

[DiagnosisID] [int] NULL,

[EvaluationID] [int] NULL,

[OccupationalID] [int] NULL,

[RecommendationID] [int] NULL,

CONSTRAINT [PK_OT_ClaimantDetails] PRIMARY KEY CLUSTERED

(

[ClaimantDetailsID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]

GO

SET ANSI_PADDING OFF

GO

ALTER TABLE [dbo].[OT_ClaimantDetails] WITH CHECK ADD CONSTRAINT [FK_OT_ClaimantDetails_OT_Benefits] FOREIGN KEY([BenefitsID])

REFERENCES [dbo].[OT_Benefits] ([BenefitsID])

GO

ALTER TABLE [dbo].[OT_ClaimantDetails] CHECK CONSTRAINT [FK_OT_ClaimantDetails_OT_Benefits]

GO

ALTER TABLE [dbo].[OT_ClaimantDetails] WITH CHECK ADD CONSTRAINT [FK_OT_ClaimantDetails_OT_ClaimantFact] FOREIGN KEY([ClaimantFactID])

REFERENCES [dbo].[OT_ClaimantFact] ([ClaimantFactID])

GO

ALTER TABLE [dbo].[OT_ClaimantDetails] CHECK CONSTRAINT [FK_OT_ClaimantDetails_OT_ClaimantFact]

GO

ALTER TABLE [dbo].[OT_ClaimantDetails] WITH CHECK ADD CONSTRAINT [FK_OT_ClaimantDetails_OT_CompanyDetails] FOREIGN KEY([CompanyDetailsID])

REFERENCES [dbo].[OT_CompanyDetails] ([CompanyDetailsID])

GO

ALTER TABLE [dbo].[OT_ClaimantDetails] CHECK CONSTRAINT [FK_OT_ClaimantDetails_OT_CompanyDetails]

GO

ALTER TABLE [dbo].[OT_ClaimantDetails] WITH CHECK ADD CONSTRAINT [FK_OT_ClaimantDetails_OT_Diagnosis] FOREIGN KEY([DiagnosisID])

REFERENCES [dbo].[OT_Diagnosis] ([DiagnosisID])

GO

ALTER TABLE [dbo].[OT_ClaimantDetails] CHECK CONSTRAINT [FK_OT_ClaimantDetails_OT_Diagnosis]

GO

ALTER TABLE [dbo].[OT_ClaimantDetails] WITH CHECK ADD CONSTRAINT [FK_OT_ClaimantDetails_OT_Evaluation] FOREIGN KEY([EvaluationID])

REFERENCES [dbo].[OT_Evaluation] ([EvaluationID])

GO

ALTER TABLE [dbo].[OT_ClaimantDetails] CHECK CONSTRAINT [FK_OT_ClaimantDetails_OT_Evaluation]

GO

ALTER TABLE [dbo].[OT_ClaimantDetails] WITH CHECK ADD CONSTRAINT [FK_OT_ClaimantDetails_OT_Occupational] FOREIGN KEY([OccupationalID])

REFERENCES [dbo].[OT_Occupational] ([OccupationalID])

GO

ALTER TABLE [dbo].[OT_ClaimantDetails] CHECK CONSTRAINT [FK_OT_ClaimantDetails_OT_Occupational]

GO

ALTER TABLE [dbo].[OT_ClaimantDetails] WITH CHECK ADD CONSTRAINT [FK_OT_ClaimantDetails_OT_OTDetails] FOREIGN KEY([ClaimantDetailsOTDetailsID])

REFERENCES [dbo].[OT_OTDetails] ([OTDetailsID])

GO

ALTER TABLE [dbo].[OT_ClaimantDetails] CHECK CONSTRAINT [FK_OT_ClaimantDetails_OT_OTDetails]

GO

ALTER TABLE [dbo].[OT_ClaimantDetails] WITH CHECK ADD CONSTRAINT [FK_OT_ClaimantDetails_OT_Recommendation] FOREIGN KEY([RecommendationID])

REFERENCES [dbo].[OT_Recommendation] ([RecommendationID])

GO

ALTER TABLE [dbo].[OT_ClaimantDetails] CHECK CONSTRAINT [FK_OT_ClaimantDetails_OT_Recommendation]

--

COLUMN OT_OTDETAILS

USE [jwest_absolutedi]

GO

/****** Object: Table [dbo].[OT_OTDetails] Script Date: 05/31/2007 17:09:58 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

SET ANSI_PADDING ON

GO

CREATE TABLE [dbo].[OT_OTDetails](

[OTDetailsID] [int] IDENTITY(1,1) NOT NULL,

[OTName] [varchar](50) NULL,

[OTLastName] [varchar](50) NULL,

[Tel] [nchar](10) NULL,

[Fax] [nchar](10) NULL,

[Cell] [nchar](10) NULL,

[Email] [varchar](50) NULL,

[City] [varchar](50) NULL,

CONSTRAINT [PK_OT_OTFact] PRIMARY KEY CLUSTERED

(

[OTDetailsID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]

GO

SET ANSI_PADDING OFF

Let me know if this helps..

THX

|||

Thanks Jackow, that helped better understand your situation.

From you original description, I think this is closer to your objective:

Code Snippet

SELECT
d.OTName
c.ClaimantFactID,
c.ClaimantDetailsOTDetailsID,
c.ReferanceDIMS,
c.DateReceived,
c.DateEntered,
c.DateCompleteCalc
FROM OT_ClaimantDetails c
JOIN OT_OTDetails d
ON c.ClaimantDetailsOTDetailsID = d.OTDetailsID

|||

Thanks jackow. Very helpful.

Exactly Arnie...looks like the original concept should be working.

|||

HI Guys,

Sorry for my delayed response. Thanks for the help. We will chat soon!!

FK is showing PK ID instead of 'Name'

I have 2 tables, OT_ClaimantDetails and OT_OTDetails. PK in OT_OTDetails is OTDetailsID which is also FK in OT_ClaimantDetails. I am trying to run a select query to display certain data but instead of displaying the Name of the OT it displays the OTDetails ID.

SELECT OT_ClaimantDetails.ClaimantFactID, OT_ClaimantDetails.ClaimantDetailsOTDetailsID, OT_ClaimantDetails.ReferanceDIMS, OT_ClaimantDetails.DateReceived, OT_ClaimantDetails.DateEntered, OT_ClaimantDetails.DateCompleteCalc
FROM OT_ClaimantDetails, OT_OTDetails
WHERE OT_ClaimantDetails.ClaimantDetailsOTDetailsID=OT_OTDetails.OTDetailsID

How should I change my query?

Is Name a column in one of the tables? If so, which one? If not, then where does it reside?

|||No, 'Name' is the users name I'm refering to. So basically instead of showing me 'ID 5' it should show me users number 5, for example, jack. In the OT_OTdetails table I have OTDetailsID and OTName. THe OTName is the 'Name' I would like to see instead of the OTDetailsID.|||

Unless there's something I'm missing you should be able to just add it to the select list.

Code Snippet

SELECT OT_ClaimantDetails.ClaimantFactID, OT_ClaimantDetails.ClaimantDetailsOTDetailsID, OT_ClaimantDetails.ReferanceDIMS, OT_ClaimantDetails.DateReceived, OT_ClaimantDetails.DateEntered, OT_ClaimantDetails.DateCompleteCalc, OT_OTDetails.OTName

|||tried it, doesn't work. What I have done, I have changed the FK (used to be OT_ClaimantDetails.OTDetailsID) to OT_ClaimantDetails.ClaimantDetailsOTDetailsID, because I received a "Ambiguous column name" error in my browser. This solved the problem to display my results again, but now I see OTDetailsID instead of the OTName.|||

Can you post your DDL?

I don't see where you're referencing any OT_OTDetails columns in your select.

This doesn't make sense.

|||

I'm new at this, what do you mean by "post DDL"?

Wouldn't the referance to the Foreign Key, "OT_ClaimantDetails.ClaimantDetailsOTDetailsID", get the data from the OT_OTDetails column?|||

DDL = Data Definition Language....your table definitions.

>>Wouldn't the referance to the Foreign Key, "OT_ClaimantDetails.ClaimantDetailsOTDetailsID", get the data from the OT_OTDetails column?

No.

But you are joining the two tables together on the OTDetailsID (in your where clause).

So columns from the OT_OTDetail should be available.


When you put OTName in the select list, do you qualify it with OT_OTDetails. (not OT_ClaimantDetails)?

|||

It would help us better assist you if you could include table DDL, query strategy used so far, sample data in the form of INSERT statements, and an illustration of the desired results. (For help with that refer to: http://www.aspfaq.com/5006 and to http://classicasp.aspfaq.com/general/how-do-i-make-sure-my-asp-question-gets-answered.html )

The less 'set up' work we have to do, the more likely you are going to have folks tackle your problem and help you. Without this effort from you, we are just playing guessing games.

|||Standby guys, I'm going to try and get the DDL posted, maybe this will help you to help me.|||

I'm using SQL 2005.

Column OT_ClaimantDetails

USE [jwest_absolutedi]

GO

/****** Object: Table [dbo].[OT_ClaimantDetails] Script Date: 05/31/2007 17:07:41 ******/

SETANSI_NULLSON

GO

SETQUOTED_IDENTIFIERON

GO

SETANSI_PADDINGON

GO

CREATETABLE [dbo].[OT_ClaimantDetails](

[ClaimantDetailsID] [int] IDENTITY(1,1)NOTNULL,

[ReferanceDIMS] [varchar](50)NULL,

[ReferanceClient] [varchar](50)NULL,

[DateReceived] [datetime] NULL,

[DateEntered] [datetime] NULL,

[DateContactClaimant] [datetime] NULL,

[DateContactClient] [datetime] NULL,

[DateAppointm] [datetime] NULL,

[DateComplExpect] [datetime] NULL,

[DateCompleteActual] [datetime] NULL,

[DateCompleteCalc] [nchar](10)NULL,

[ReportOT] [varchar](250)NULL,

[ReportClient] [varchar](250)NULL,

[ClaimantFactID] [int] NULL,

[CompanyDetailsID] [int] NULL,

[ClaimantDetailsOTDetailsID] [int] NULL,

[BenefitsID] [int] NULL,

[DiagnosisID] [int] NULL,

[EvaluationID] [int] NULL,

[OccupationalID] [int] NULL,

[RecommendationID] [int] NULL,

CONSTRAINT [PK_OT_ClaimantDetails] PRIMARYKEYCLUSTERED

(

[ClaimantDetailsID] ASC

)WITH(PAD_INDEX=OFF,STATISTICS_NORECOMPUTE=OFF,IGNORE_DUP_KEY=OFF,ALLOW_ROW_LOCKS=ON,ALLOW_PAGE_LOCKS=ON)ON [PRIMARY]

)ON [PRIMARY]

GO

SETANSI_PADDINGOFF

GO

ALTERTABLE [dbo].[OT_ClaimantDetails] WITHCHECKADDCONSTRAINT [FK_OT_ClaimantDetails_OT_Benefits] FOREIGNKEY([BenefitsID])

REFERENCES [dbo].[OT_Benefits] ([BenefitsID])

GO

ALTERTABLE [dbo].[OT_ClaimantDetails] CHECKCONSTRAINT [FK_OT_ClaimantDetails_OT_Benefits]

GO

ALTERTABLE [dbo].[OT_ClaimantDetails] WITHCHECKADDCONSTRAINT [FK_OT_ClaimantDetails_OT_ClaimantFact] FOREIGNKEY([ClaimantFactID])

REFERENCES [dbo].[OT_ClaimantFact] ([ClaimantFactID])

GO

ALTERTABLE [dbo].[OT_ClaimantDetails] CHECKCONSTRAINT [FK_OT_ClaimantDetails_OT_ClaimantFact]

GO

ALTERTABLE [dbo].[OT_ClaimantDetails] WITHCHECKADDCONSTRAINT [FK_OT_ClaimantDetails_OT_CompanyDetails] FOREIGNKEY([CompanyDetailsID])

REFERENCES [dbo].[OT_CompanyDetails] ([CompanyDetailsID])

GO

ALTERTABLE [dbo].[OT_ClaimantDetails] CHECKCONSTRAINT [FK_OT_ClaimantDetails_OT_CompanyDetails]

GO

ALTERTABLE [dbo].[OT_ClaimantDetails] WITHCHECKADDCONSTRAINT [FK_OT_ClaimantDetails_OT_Diagnosis] FOREIGNKEY([DiagnosisID])

REFERENCES [dbo].[OT_Diagnosis] ([DiagnosisID])

GO

ALTERTABLE [dbo].[OT_ClaimantDetails] CHECKCONSTRAINT [FK_OT_ClaimantDetails_OT_Diagnosis]

GO

ALTERTABLE [dbo].[OT_ClaimantDetails] WITHCHECKADDCONSTRAINT [FK_OT_ClaimantDetails_OT_Evaluation] FOREIGNKEY([EvaluationID])

REFERENCES [dbo].[OT_Evaluation] ([EvaluationID])

GO

ALTERTABLE [dbo].[OT_ClaimantDetails] CHECKCONSTRAINT [FK_OT_ClaimantDetails_OT_Evaluation]

GO

ALTERTABLE [dbo].[OT_ClaimantDetails] WITHCHECKADDCONSTRAINT [FK_OT_ClaimantDetails_OT_Occupational] FOREIGNKEY([OccupationalID])

REFERENCES [dbo].[OT_Occupational] ([OccupationalID])

GO

ALTERTABLE [dbo].[OT_ClaimantDetails] CHECKCONSTRAINT [FK_OT_ClaimantDetails_OT_Occupational]

GO

ALTERTABLE [dbo].[OT_ClaimantDetails] WITHCHECKADDCONSTRAINT [FK_OT_ClaimantDetails_OT_OTDetails] FOREIGNKEY([ClaimantDetailsOTDetailsID])

REFERENCES [dbo].[OT_OTDetails] ([OTDetailsID])

GO

ALTERTABLE [dbo].[OT_ClaimantDetails] CHECKCONSTRAINT [FK_OT_ClaimantDetails_OT_OTDetails]

GO

ALTERTABLE [dbo].[OT_ClaimantDetails] WITHCHECKADDCONSTRAINT [FK_OT_ClaimantDetails_OT_Recommendation] FOREIGNKEY([RecommendationID])

REFERENCES [dbo].[OT_Recommendation] ([RecommendationID])

GO

ALTERTABLE [dbo].[OT_ClaimantDetails] CHECKCONSTRAINT [FK_OT_ClaimantDetails_OT_Recommendation]

--

COLUMN OT_OTDETAILS

USE [jwest_absolutedi]

GO

/****** Object: Table [dbo].[OT_OTDetails] Script Date: 05/31/2007 17:09:58 ******/

SETANSI_NULLSON

GO

SETQUOTED_IDENTIFIERON

GO

SETANSI_PADDINGON

GO

CREATETABLE [dbo].[OT_OTDetails](

[OTDetailsID] [int] IDENTITY(1,1)NOTNULL,

[OTName] [varchar](50)NULL,

[OTLastName] [varchar](50)NULL,

[Tel] [nchar](10)NULL,

[Fax] [nchar](10)NULL,

[Cell] [nchar](10)NULL,

[Email] [varchar](50)NULL,

[City] [varchar](50)NULL,

CONSTRAINT [PK_OT_OTFact] PRIMARYKEYCLUSTERED

(

[OTDetailsID] ASC

)WITH(PAD_INDEX=OFF,STATISTICS_NORECOMPUTE=OFF,IGNORE_DUP_KEY=OFF,ALLOW_ROW_LOCKS=ON,ALLOW_PAGE_LOCKS=ON)ON [PRIMARY]

)ON [PRIMARY]

GO

SETANSI_PADDINGOFF

Let me know if this helps..

THX

|||

Thanks Jackow, that helped better understand your situation.

From you original description, I think this is closer to your objective:

Code Snippet

SELECT
d.OTName
c.ClaimantFactID,
c.ClaimantDetailsOTDetailsID,
c.ReferanceDIMS,
c.DateReceived,
c.DateEntered,
c.DateCompleteCalc
FROM OT_ClaimantDetails c
JOIN OT_OTDetails d
ON c.ClaimantDetailsOTDetailsID = d.OTDetailsID

|||

Thanks jackow. Very helpful.

Exactly Arnie...looks like the original concept should be working.

|||

HI Guys,

Sorry for my delayed response. Thanks for the help. We will chat soon!!

2012年3月11日星期日

Fixed decimal convertion

I am trying to show latitude and longitude with 5 decimal points. Now its showing (for example: 55.744025477, -4.1256633333333 etc.). How do I get data in 5 decimal points?

Your help with example would be appreciated.

aspx code:

<asp:GridView ID="GridView1" runat="server" DataSourceID="odsGPS" AllowPaging="true" AllowSorting="true"
AutoGenerateColumns="False" CellPadding="1" CellSpacing="1" BackColor="White" GridLines="None"
BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" PageSize="20" Width="100%" Font-Size="8pt"
OnLoad="GridView1_Load" >
<Columns>
<asp:TemplateField HeaderText="Show">
<ItemTemplate>
<asp:CheckBox ID="CheckBox2" onclick="MarkerForThisRow(this);" ToolTip="Click to show on map." runat="server" OnCheckedChanged="CheckBox2_CheckedChanged" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:TemplateField>

<asp:BoundField DataField="Latitude" HeaderText="Latitude ( ° )" >
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>


<asp:BoundField DataField="Longitude" HeaderText="Longitude ( ° )" >
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>

In your <asp:BoundField /> for the Latitude, add the following:

DataFormatString="{0:F5}"

F represents a fixed decimal, and 5 represents the number of decimal places

|||

On your gridview open the gridview task with clicking little arrow on the right upper corner.

Then click Edit Columns
Then select your field "Latitude",
Then on the right, scroll down and come to Data section.
Change the dataFormatString as {0:N5}
Also you will see another property under Behavior section which is "HtmlEncode" make it false...

Let me know if it does not work...


|||

Thanks a lot guys for your help.

In the mean time, I found another way to do it. Using Convert.ToDecimal in a Item Template also does the job.

<asp:TemplateField HeaderText="Latitude ( ° )">
<ItemTemplate>
<%# Convert.ToDecimal(Eval("Latitude")).ToString("0.00000") %>
</ItemTemplate></asp:TemplateField>

|||

Hiavci,

It did not work in my case.

|||

Hi,

It must work.I already tried and it's working.

Did you make HTMLEncode=False ?|||

I did. But may be I am missing something else.

<asp:BoundField DataField="Latitude" HeaderText="Latitude " DataFormatString="{0:N5}" HtmlEncode="False" >
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>

|||

Datafield "Latitude" is not defined varchar or text in the database,right?
Can you check its type in the database?

|||

GPSID int Unchecked
VehicleID int Unchecked
Latitude varchar(50) Unchecked
Longitude varchar(50) Unchecked
GPSTime datetime Checked
ServerTime datetime Unchecked
Valid bit Unchecked

|||

If those two are varchars, you will not be able to write them as decimals.That property we said will not work. You have to change their type to int, or decimal.