I am converting a large application so that it can run with SQL server and
Access via ADO into Delphi.
There are many places where it does "select table1.*, table2.* etc"
With Access if there are duplicate field names (e.g. "description") they are
returned fully qualified and you can reference them as "table1.description"
and "table2.description".
I have just discovered to my horror that SQL server will not qualify the
names for you and returns these field names as "description" and
"description1".
Is there any way of altering this behaviour to return the fully qualified
field names as with Access ?
I know I should rewrite the queries to give aliases to the fields but there
maybe 1000's of places in the code and I want to avoid this.
Thanks for any helpHi Andrew,
I am not sure I understood your issue.
Could you place DDL + Sample Data?
What I did not understand is where are the queries writen? In Access Queries
? In Delphi code? In Stored Procedures?
I hope I can help you if I get a better idea of the issue.
Bye,|||you must do it manually (and you always should in SQL)
Access protects the users from themselves. SQL doesnt protect you as much.
You can alias any field name with the "AS" key word:
SELECT MyField AS ThisName
Hope this helps
Greg Jackson
PDX, Oregonsql
Showing posts with label converting. Show all posts
Showing posts with label converting. Show all posts
Wednesday, March 28, 2012
Problem with SQL select with duplicate field names
I am converting a large application so that it can run with SQL server and
Access via ADO into Delphi.
There are many places where it does "select table1.*, table2.* etc"
With Access if there are duplicate field names (e.g. "description") they are
returned fully qualified and you can reference them as "table1.description"
and "table2.description".
I have just discovered to my horror that SQL server will not qualify the
names for you and returns these field names as "description" and
"description1".
Is there any way of altering this behaviour to return the fully qualified
field names as with Access ?
I know I should rewrite the queries to give aliases to the fields but there
maybe 1000's of places in the code and I want to avoid this.
Thanks for any helpyou must do it manually (and you always should in SQL)
Access protects the users from themselves. SQL doesnt protect you as much.
You can alias any field name with the "AS" key word:
SELECT MyField AS ThisName
Hope this helps
Greg Jackson
PDX, Oregon
Access via ADO into Delphi.
There are many places where it does "select table1.*, table2.* etc"
With Access if there are duplicate field names (e.g. "description") they are
returned fully qualified and you can reference them as "table1.description"
and "table2.description".
I have just discovered to my horror that SQL server will not qualify the
names for you and returns these field names as "description" and
"description1".
Is there any way of altering this behaviour to return the fully qualified
field names as with Access ?
I know I should rewrite the queries to give aliases to the fields but there
maybe 1000's of places in the code and I want to avoid this.
Thanks for any helpyou must do it manually (and you always should in SQL)
Access protects the users from themselves. SQL doesnt protect you as much.
You can alias any field name with the "AS" key word:
SELECT MyField AS ThisName
Hope this helps
Greg Jackson
PDX, Oregon
Wednesday, March 21, 2012
Problem with sp and uniqueidentifier
Hi,
I use this procedure to add a record to the db (SQL 2005)
i constantly get this error:
Conversion failed when converting from a character string to uniqueidentifier.
This is the sp:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROC [dbo].[AddBootloader]
@.BootName nvarchar(50),
@.Version nvarchar(50),
@.CSD nvarchar(50),
@.CreatorID uniqueidentifier,
@.FilePath nvarchar(150),
@.FileSize nvarchar(150)
AS
INSERT INTO dbo.EB_Bootloaders
([Bootname]
,[Version]
,[CSD]
,[FilePath]
,[FileSize]
,[CreatorID])
VALUES
(
@.BootName,
@.Version,
@.CSD,
@.CreatorID,
@.FilePath,
@.FileSize)
And this is the table:
USE [Ebdata]
GO
/****** Object: Table [dbo].[EB_Bootloaders] Script Date: 07/12/2006 10:06:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EB_Bootloaders](
[ID] [bigint] IDENTITY(1,3) NOT NULL,
[BootName] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL,
[Version] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL,
[CSD] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL,
[FilePath] [nvarchar](150) COLLATE Latin1_General_CI_AS NULL,
[FileSize] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL,
[CreateDate] [datetime] NULL CONSTRAINT [DF_EB_Bootloaders_CreateDate] DEFAULT (getdate()),
[CreatorID] [uniqueidentifier] NOT NULL,
[UpdateDate] [datetime] NULL,
[UpdateUser] [uniqueidentifier] NULL,
CONSTRAINT [PK_EB_Bootloaders_1] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
USE [Ebdata]
GO
ALTER TABLE [dbo].[EB_Bootloaders] WITH NOCHECK ADD CONSTRAINT [FK_EB_Bootloaders_aspnet_Users] FOREIGN KEY([CreatorID])
REFERENCES [dbo].[aspnet_Users] ([UserId])
NOT FOR REPLICATION
GO
ALTER TABLE [dbo].[EB_Bootloaders] WITH NOCHECK ADD CONSTRAINT [FK_EB_Bootloaders_aspnet_Users1] FOREIGN KEY([UpdateUser])
REFERENCES [dbo].[aspnet_Users] ([UserId])
NOT FOR REPLICATION
The funny thing is that i copied the sp code from another which runs perfect,
I insert a Guid from an asp.net page.
Hope someone can help me here because im am stucked!
Cheers WimmoHi Wimmo
Aren't your VALUES in your insert statement in the wrong order (@.CreatorID should be last not fourth)?|||set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROC [dbo].[AddBootloader]
@.BootName nvarchar(50),
@.Version nvarchar(50),
@.CSD nvarchar(50),
@.CreatorID uniqueidentifier,
@.FilePath nvarchar(150),
@.FileSize nvarchar(150)
AS
INSERT INTO dbo.EB_Bootloaders
([Bootname]
,[Version]
,[CSD]
,[CreatorID]
,[FilePath]
,[FileSize]
)
VALUES
(
@.BootName,
@.Version,
@.CSD,
@.CreatorID,
@.FilePath,
@.FileSize)|||Euh thanx, think i was sleeping!
Glad some people are awake!
Thanx for helping me!
cheers Wim
I use this procedure to add a record to the db (SQL 2005)
i constantly get this error:
Conversion failed when converting from a character string to uniqueidentifier.
This is the sp:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROC [dbo].[AddBootloader]
@.BootName nvarchar(50),
@.Version nvarchar(50),
@.CSD nvarchar(50),
@.CreatorID uniqueidentifier,
@.FilePath nvarchar(150),
@.FileSize nvarchar(150)
AS
INSERT INTO dbo.EB_Bootloaders
([Bootname]
,[Version]
,[CSD]
,[FilePath]
,[FileSize]
,[CreatorID])
VALUES
(
@.BootName,
@.Version,
@.CSD,
@.CreatorID,
@.FilePath,
@.FileSize)
And this is the table:
USE [Ebdata]
GO
/****** Object: Table [dbo].[EB_Bootloaders] Script Date: 07/12/2006 10:06:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EB_Bootloaders](
[ID] [bigint] IDENTITY(1,3) NOT NULL,
[BootName] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL,
[Version] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL,
[CSD] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL,
[FilePath] [nvarchar](150) COLLATE Latin1_General_CI_AS NULL,
[FileSize] [nvarchar](50) COLLATE Latin1_General_CI_AS NULL,
[CreateDate] [datetime] NULL CONSTRAINT [DF_EB_Bootloaders_CreateDate] DEFAULT (getdate()),
[CreatorID] [uniqueidentifier] NOT NULL,
[UpdateDate] [datetime] NULL,
[UpdateUser] [uniqueidentifier] NULL,
CONSTRAINT [PK_EB_Bootloaders_1] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
USE [Ebdata]
GO
ALTER TABLE [dbo].[EB_Bootloaders] WITH NOCHECK ADD CONSTRAINT [FK_EB_Bootloaders_aspnet_Users] FOREIGN KEY([CreatorID])
REFERENCES [dbo].[aspnet_Users] ([UserId])
NOT FOR REPLICATION
GO
ALTER TABLE [dbo].[EB_Bootloaders] WITH NOCHECK ADD CONSTRAINT [FK_EB_Bootloaders_aspnet_Users1] FOREIGN KEY([UpdateUser])
REFERENCES [dbo].[aspnet_Users] ([UserId])
NOT FOR REPLICATION
The funny thing is that i copied the sp code from another which runs perfect,
I insert a Guid from an asp.net page.
Hope someone can help me here because im am stucked!
Cheers WimmoHi Wimmo
Aren't your VALUES in your insert statement in the wrong order (@.CreatorID should be last not fourth)?|||set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROC [dbo].[AddBootloader]
@.BootName nvarchar(50),
@.Version nvarchar(50),
@.CSD nvarchar(50),
@.CreatorID uniqueidentifier,
@.FilePath nvarchar(150),
@.FileSize nvarchar(150)
AS
INSERT INTO dbo.EB_Bootloaders
([Bootname]
,[Version]
,[CSD]
,[CreatorID]
,[FilePath]
,[FileSize]
)
VALUES
(
@.BootName,
@.Version,
@.CSD,
@.CreatorID,
@.FilePath,
@.FileSize)|||Euh thanx, think i was sleeping!
Glad some people are awake!
Thanx for helping me!
cheers Wim
Labels:
character,
constantly,
converting,
database,
errorconversion,
failed,
microsoft,
mysql,
oracle,
procedure,
record,
server,
sql,
string,
uniqueidentifier
Subscribe to:
Posts (Atom)