SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


t-SQL query (convert to 2005)


t-SQL query (convert to 2005)

Author
Message
river1
river1
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1762 Visits: 1366
Hi all,

I have a database in SQL Server 2000.
I run this query:

SELECT CODCTB, NOTA.NUMDU, TIPODLI, SOMA, MIN(SGTALIQDATA.CODLIQ) CODLIQ FROM
((SGTALIQDATA INNER JOIN LIQUIDACAO ON SGTALIQDATA.CODLIQ = LIQUIDACAO.CODLIQ)
INNER JOIN (SELECT SUM(IMPTRIB-IMPCOB) SOMA, NUMDU FROM (SGTALIQDATA
INNER JOIN LIQUIDACAO ON SGTALIQDATA.CODLIQ = LIQUIDACAO.CODLIQ)
GROUP BY NUMDU) as NOTA ON NOTA.NUMDU = SGTALIQDATA.NUMDU)
INNER JOIN (SELECT NUMDU, DATAEXPIRACAO_FINAL FROM
(SELECT NUMDU_STUF, MAX(DATAEXPIRACAO) DATAEXPIRACAO_FINAL FROM
( SELECT DISTINCT NUMDU, STUFF(NUMDU, 13, 2, RIGHT(NUMDU, 1))NUMDU_STUF, DATAEXPIRACAO FROM SGTALIQDATA
Where (IsNumeric(SUBSTRING(NUMDU, Len(NUMDU), 1)) = 0)
Union SELECT DISTINCT NUMDU, NUMDU NUMDU_STUF, DATAEXPIRACAO FROM SGTALIQDATA
WHERE (ISNUMERIC(SUBSTRING(NUMDU, LEN(NUMDU), 1))=1) AND DUORIGINAL IS NULL
Union SELECT DISTINCT NUMDU, DUORIGINAL NUMDU_STUF, DATAEXPIRACAO FROM SGTALIQDATA
WHERE (ISNUMERIC(SUBSTRING(NUMDU, LEN(NUMDU), 1))=1) AND LEN(DUORIGINAL)<14
Union SELECT DISTINCT NUMDU, ISNULL(STUFF(DUORIGINAL, LEN(DUORIGINAL)-1, 2, RIGHT(DUORIGINAL, 1)), NUMDU) NUMDU_STUF, DATAEXPIRACAO
FROM SGTALIQDATA WHERE (ISNUMERIC(SUBSTRING(NUMDU, LEN(NUMDU), 1))=1) AND LEN(DUORIGINAL)>=14 ) AS DATA_EXPIRA_DU1
GROUP BY NUMDU_STUF) AS X INNER JOIN (SELECT NUMDU, NUMDU_STUF FROM
( SELECT DISTINCT NUMDU, STUFF(NUMDU, 13, 2, RIGHT(NUMDU, 1))NUMDU_STUF, DATAEXPIRACAO FROM SGTALIQDATA
Where (IsNumeric(SUBSTRING(NUMDU, Len(NUMDU), 1)) = 0)
Union SELECT DISTINCT NUMDU, NUMDU NUMDU_STUF, DATAEXPIRACAO FROM SGTALIQDATA
WHERE (ISNUMERIC(SUBSTRING(NUMDU, LEN(NUMDU), 1))=1) AND DUORIGINAL IS NULL
Union SELECT DISTINCT NUMDU, DUORIGINAL NUMDU_STUF, DATAEXPIRACAO FROM SGTALIQDATA
WHERE (ISNUMERIC(SUBSTRING(NUMDU, LEN(NUMDU), 1))=1) AND LEN(DUORIGINAL)<14
Union SELECT DISTINCT NUMDU, ISNULL(STUFF(DUORIGINAL, LEN(DUORIGINAL)-1, 2, RIGHT(DUORIGINAL, 1)), NUMDU) NUMDU_STUF, DATAEXPIRACAO
FROM SGTALIQDATA WHERE (ISNUMERIC(SUBSTRING(NUMDU, LEN(NUMDU), 1))=1) AND LEN(DUORIGINAL)>=14 ) AS DATA_EXPIRA_DU2) AS Y
ON X.NUMDU_STUF = Y.NUMDU_STUF) AS ULTIMANOTA
ON NOTA.NUMDU = ULTIMANOTA.NUMDU
AND LIQUIDACAO.CodCR IS NULL AND SGTALIQDATA.CodCR IS NULL
AND (LIQUIDACAO.IMPTRIB <> LIQUIDACAO.IMPCOB) AND LIQUIDACAO.CodAnula IS NULL
AND ULTIMANOTA.DATAEXPIRACAO_FINAL < '2009-6-01'
GROUP BY CODCTB, NOTA.NUMDU, TIPODLI, SOMA ORDER BY NOTA.CODLIQ DESC




The query runs sucessfull. when i run it on the same database but in SQL Server 2005 (with the exact same columns and data) i receive this error:



Msg 207, Level 16, State 1, Line 30
Invalid column name 'CODLIQ'.




Can someone help, please?


thank you
Animal Magic
Animal Magic
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1590 Visits: 13731
can you post the table definitions for SGTALIQDATA and LIQUIDACAO from both the sql 2000 and the sql 2005 databases
river1
river1
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1762 Visits: 1366
what do you mean with tables definitions?
The field names and data types?

thank you
Animal Magic
Animal Magic
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1590 Visits: 13731
yes, if you use SSMS and go to the table, right click and produce a create script to a new window. then copy and paste that in to a reply on here. do that for both tables on both databases
river1
river1
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1762 Visits: 1366
SQL Server 2005 (script produced trought management studio):


table SGTALIQDATA:


USE [SGT]
GO
/****** Object: Table [dbo].[SGTALIQDATA] Script Date: 08/14/2009 13:59:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[SGTALIQDATA](
[CODLIQ] [int] NOT NULL,
[ANONOTAS] [int] NULL,
[ESTANCIA] [varchar](5) NULL,
[DATAEMISSAO] [datetime] NOT NULL,
[NUMDU] [varchar](20) NOT NULL,
[DATAEXPIRACAO] [datetime] NOT NULL,
[CODCTBIRREG] [int] NULL,
[NOMEFICH] [varchar](20) NULL,
[DUORIGINAL] [varchar](20) NULL,
[TIPOID] [int] NOT NULL CONSTRAINT [DF_SGTALIQDATA_TIPOID] DEFAULT (1),
[CODCR] [int] NULL,
[NUMLIVRE] [varchar](20) NULL,
[DUORIGINAL2] [varchar](20) NULL,
[SEPARADO] [varchar](20) NULL,
[CODDESP] [int] NULL,
[CODAREASERVICO] [int] NULL,
CONSTRAINT [IX_SGTALIQDATA] UNIQUE CLUSTERED
(
[CODLIQ] DESC
)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
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Armazena o nº da nota que originou a liquidação adicional' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SGTALIQDATA', @level2type=N'COLUMN',@level2name=N'DUORIGINAL'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ID utilizada na importacao do fich. 1=NIF, 2=RGC' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SGTALIQDATA', @level2type=N'COLUMN',@level2name=N'TIPOID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Armazena o nº da nota que originou a liquidação oficiosa (não adicional)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SGTALIQDATA', @level2type=N'COLUMN',@level2name=N'DUORIGINAL2'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Número do separado de bagagem' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SGTALIQDATA', @level2type=N'COLUMN',@level2name=N'SEPARADO'
GO
ALTER TABLE [dbo].[SGTALIQDATA] WITH CHECK ADD CONSTRAINT [FK_SGTALIQDATA_AREASERVICO] FOREIGN KEY([CODAREASERVICO])
REFERENCES [dbo].[AREASERVICO] ([CODAREASERVICO])
GO
ALTER TABLE [dbo].[SGTALIQDATA] CHECK CONSTRAINT [FK_SGTALIQDATA_AREASERVICO]
GO
ALTER TABLE [dbo].[SGTALIQDATA] WITH NOCHECK ADD CONSTRAINT [FK_SGTALIQDATA_DESPACHANTES] FOREIGN KEY([CODDESP])
REFERENCES [dbo].[DESPACHANTES] ([codDesp])
GO
ALTER TABLE [dbo].[SGTALIQDATA] CHECK CONSTRAINT [FK_SGTALIQDATA_DESPACHANTES]




table Liquidacao:

/****** Object: Table [dbo].[LIQUIDACAO] Script Date: 08/14/2009 14:02:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[LIQUIDACAO](
[CODLIQ] [int] IDENTITY(1,1) NOT NULL,
[NUMLIQ] [varchar](50) NOT NULL,
[LANCLIQ] [int] NOT NULL,
[DATALIQ] [datetime] NOT NULL,
[HORALIQ] [datetime] NOT NULL,
[VALORTRIB] [float] NOT NULL,
[CODCTB] [int] NOT NULL,
[CODRF] [int] NULL,
[CODFUNC] [int] NULL,
[DATALIQANUL] [datetime] NULL,
[HORALIQANUL] [datetime] NULL,
[CODARF] [int] NULL,
[CODAFUNC] [int] NULL,
[DIASJUROS] [float] NULL,
[TAXAMENSALJUROS] [float] NULL,
[CODIMP] [int] NULL,
[ANOLIQ] [varchar](50) NOT NULL,
[DESCPERIODO] [varchar](50) NOT NULL,
[CODPERIODO] [int] NULL,
[CODTLIQ1] [int] NULL,
[CODTLIQ2] [int] NULL,
[TXTRIB] [float] NULL,
[IMPTRIB] [float] NOT NULL,
[VALORJUROS] [float] NULL,
[JUROSPAGAR] [float] NULL,
[MULTAID] [char](50) NULL,
[MULTAVALOR] [float] NULL,
[CUSTAID] [char](50) NULL,
[CUSTAVALOR] [float] NULL,
[IMPCOB] [float] NULL CONSTRAINT [DF__LIQUIDACA__IMPCO__48CFD27E] DEFAULT (0),
[IMPPAGAR] [float] NULL CONSTRAINT [DF__LIQUIDACA__IMPPA__49C3F6B7] DEFAULT (0),
[CODDAR] [int] NULL,
[CODNOTIFICA] [int] NULL,
[CODCR] [int] NULL,
[CODTPAG] [int] NULL,
[PAGEFECT] [float] NOT NULL CONSTRAINT [DF__LIQUIDACA__PAGEF__4AB81AF0] DEFAULT (0),
[CODDLIORIG] [int] NULL,
[TIPODLI] [float] NOT NULL,
[CODCRORIG] [int] NULL,
[CODANULA] [int] NULL,
CONSTRAINT [PK__LIQUIDACAO__46E78A0C] PRIMARY KEY CLUSTERED
(
[CODLIQ] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [AK_LIQUIDACAO_LANCLIQ] UNIQUE NONCLUSTERED
(
[LANCLIQ] ASC,
[DATALIQ] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [AK_LIQUIDACAO_NUMLIQ] UNIQUE NONCLUSTERED
(
[NUMLIQ] 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].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODAF__3864608B] FOREIGN KEY([CODAFUNC])
REFERENCES [dbo].[FUNCIONARIO] ([CODFUNC])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODAF__3864608B]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODCR__32AB8735] FOREIGN KEY([CODCR])
REFERENCES [dbo].[CRELAXE] ([CODCR])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODCR__32AB8735]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODCR__339FAB6E] FOREIGN KEY([CODCRORIG])
REFERENCES [dbo].[CRELAXE] ([CODCR])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODCR__339FAB6E]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODDL__489AC854] FOREIGN KEY([CODDLIORIG])
REFERENCES [dbo].[LIQUIDACAO] ([CODLIQ])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODDL__489AC854]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODFU__395884C4] FOREIGN KEY([CODFUNC])
REFERENCES [dbo].[FUNCIONARIO] ([CODFUNC])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODFU__395884C4]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODIM__40F9A68C] FOREIGN KEY([CODIMP])
REFERENCES [dbo].[IMPOSTO] ([CODIMP])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODIM__40F9A68C]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODNO__4E53A1AA] FOREIGN KEY([CODNOTIFICA])
REFERENCES [dbo].[NOTIFICACAO] ([CODNOTIFICA])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODNO__4E53A1AA]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODPE__51300E55] FOREIGN KEY([CODPERIODO])
REFERENCES [dbo].[PERIODICIDADE] ([CODPERIODO])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODPE__51300E55]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODTL__531856C7] FOREIGN KEY([CODTLIQ2])
REFERENCES [dbo].[TLIQUIDACAO] ([CODTLIQ])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODTL__531856C7]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODTP__55F4C372] FOREIGN KEY([CODTPAG])
REFERENCES [dbo].[TPAGAMENTO] ([CODTPAG])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODTP__55F4C372]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [CK__LIQUIDACA__CODTL__47DBAE45] CHECK (([CODTLIQ1] = 1 or [CODTLIQ1] = 0))
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [CK__LIQUIDACA__CODTL__47DBAE45]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [CK__LIQUIDACA__PAGEF__4BAC3F29] CHECK (([PAGEFECT] = 1 or [PAGEFECT] = 0))
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [CK__LIQUIDACA__PAGEF__4BAC3F29]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [CK__LIQUIDACA__TIPOD__4CA06362] CHECK (([TIPODLI] = 1 or [TIPODLI] = 0))
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [CK__LIQUIDACA__TIPOD__4CA06362]






Script SQL Server 2000 (trought management studio):


table SGTALIQDATA:

USE [SGT]
GO
/****** Object: Table [dbo].[SGTALIQDATA] Script Date: 08/14/2009 14:07:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[SGTALIQDATA](
[CODLIQ] [int] NOT NULL,
[ANONOTAS] [int] NULL,
[ESTANCIA] [varchar](5) NULL,
[DATAEMISSAO] [datetime] NOT NULL,
[NUMDU] [varchar](20) NOT NULL,
[DATAEXPIRACAO] [datetime] NOT NULL,
[CODCTBIRREG] [int] NULL,
[NOMEFICH] [varchar](20) NULL,
[DUORIGINAL] [varchar](20) NULL,
[TIPOID] [int] NOT NULL CONSTRAINT [DF_SGTALIQDATA_TIPOID] DEFAULT (1),
[CODCR] [int] NULL,
[NUMLIVRE] [varchar](20) NULL,
[DUORIGINAL2] [varchar](20) NULL,
[SEPARADO] [varchar](20) NULL,
[CODDESP] [int] NULL,
[CODAREASERVICO] [int] NULL,
CONSTRAINT [IX_SGTALIQDATA] UNIQUE CLUSTERED
(
[CODLIQ] DESC
)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
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Armazena o nº da nota que originou a liquidação adicional' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SGTALIQDATA', @level2type=N'COLUMN',@level2name=N'DUORIGINAL'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'ID utilizada na importacao do fich. 1=NIF, 2=RGC' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SGTALIQDATA', @level2type=N'COLUMN',@level2name=N'TIPOID'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Armazena o nº da nota que originou a liquidação oficiosa (não adicional)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SGTALIQDATA', @level2type=N'COLUMN',@level2name=N'DUORIGINAL2'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Número do separado de bagagem' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SGTALIQDATA', @level2type=N'COLUMN',@level2name=N'SEPARADO'
GO
ALTER TABLE [dbo].[SGTALIQDATA] WITH CHECK ADD CONSTRAINT [FK_SGTALIQDATA_AREASERVICO] FOREIGN KEY([CODAREASERVICO])
REFERENCES [dbo].[AREASERVICO] ([CODAREASERVICO])
GO
ALTER TABLE [dbo].[SGTALIQDATA] CHECK CONSTRAINT [FK_SGTALIQDATA_AREASERVICO]
GO
ALTER TABLE [dbo].[SGTALIQDATA] WITH NOCHECK ADD CONSTRAINT [FK_SGTALIQDATA_DESPACHANTES] FOREIGN KEY([CODDESP])
REFERENCES [dbo].[DESPACHANTES] ([codDesp])
GO
ALTER TABLE [dbo].[SGTALIQDATA] CHECK CONSTRAINT [FK_SGTALIQDATA_DESPACHANTES]


table liquidacao:


USE [SGT]
GO
/****** Object: Table [dbo].[LIQUIDACAO] Script Date: 08/14/2009 14:08:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[LIQUIDACAO](
[CODLIQ] [int] IDENTITY(1,1) NOT NULL,
[NUMLIQ] [varchar](50) NOT NULL,
[LANCLIQ] [int] NOT NULL,
[DATALIQ] [datetime] NOT NULL,
[HORALIQ] [datetime] NOT NULL,
[VALORTRIB] [float] NOT NULL,
[CODCTB] [int] NOT NULL,
[CODRF] [int] NULL,
[CODFUNC] [int] NULL,
[DATALIQANUL] [datetime] NULL,
[HORALIQANUL] [datetime] NULL,
[CODARF] [int] NULL,
[CODAFUNC] [int] NULL,
[DIASJUROS] [float] NULL,
[TAXAMENSALJUROS] [float] NULL,
[CODIMP] [int] NULL,
[ANOLIQ] [varchar](50) NOT NULL,
[DESCPERIODO] [varchar](50) NOT NULL,
[CODPERIODO] [int] NULL,
[CODTLIQ1] [int] NULL,
[CODTLIQ2] [int] NULL,
[TXTRIB] [float] NULL,
[IMPTRIB] [float] NOT NULL,
[VALORJUROS] [float] NULL,
[JUROSPAGAR] [float] NULL,
[MULTAID] [char](50) NULL,
[MULTAVALOR] [float] NULL,
[CUSTAID] [char](50) NULL,
[CUSTAVALOR] [float] NULL,
[IMPCOB] [float] NULL CONSTRAINT [DF__LIQUIDACA__IMPCO__48CFD27E] DEFAULT (0),
[IMPPAGAR] [float] NULL CONSTRAINT [DF__LIQUIDACA__IMPPA__49C3F6B7] DEFAULT (0),
[CODDAR] [int] NULL,
[CODNOTIFICA] [int] NULL,
[CODCR] [int] NULL,
[CODTPAG] [int] NULL,
[PAGEFECT] [float] NOT NULL CONSTRAINT [DF__LIQUIDACA__PAGEF__4AB81AF0] DEFAULT (0),
[CODDLIORIG] [int] NULL,
[TIPODLI] [float] NOT NULL,
[CODCRORIG] [int] NULL,
[CODANULA] [int] NULL,
CONSTRAINT [PK__LIQUIDACAO__46E78A0C] PRIMARY KEY CLUSTERED
(
[CODLIQ] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [AK_LIQUIDACAO_LANCLIQ] UNIQUE NONCLUSTERED
(
[LANCLIQ] ASC,
[DATALIQ] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [AK_LIQUIDACAO_NUMLIQ] UNIQUE NONCLUSTERED
(
[NUMLIQ] 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].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODAF__3864608B] FOREIGN KEY([CODAFUNC])
REFERENCES [dbo].[FUNCIONARIO] ([CODFUNC])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODAF__3864608B]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODCR__32AB8735] FOREIGN KEY([CODCR])
REFERENCES [dbo].[CRELAXE] ([CODCR])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODCR__32AB8735]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODCR__339FAB6E] FOREIGN KEY([CODCRORIG])
REFERENCES [dbo].[CRELAXE] ([CODCR])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODCR__339FAB6E]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODDL__489AC854] FOREIGN KEY([CODDLIORIG])
REFERENCES [dbo].[LIQUIDACAO] ([CODLIQ])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODDL__489AC854]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODFU__395884C4] FOREIGN KEY([CODFUNC])
REFERENCES [dbo].[FUNCIONARIO] ([CODFUNC])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODFU__395884C4]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODIM__40F9A68C] FOREIGN KEY([CODIMP])
REFERENCES [dbo].[IMPOSTO] ([CODIMP])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODIM__40F9A68C]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODNO__4E53A1AA] FOREIGN KEY([CODNOTIFICA])
REFERENCES [dbo].[NOTIFICACAO] ([CODNOTIFICA])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODNO__4E53A1AA]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODPE__51300E55] FOREIGN KEY([CODPERIODO])
REFERENCES [dbo].[PERIODICIDADE] ([CODPERIODO])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODPE__51300E55]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODTL__531856C7] FOREIGN KEY([CODTLIQ2])
REFERENCES [dbo].[TLIQUIDACAO] ([CODTLIQ])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODTL__531856C7]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [FK__LIQUIDACA__CODTP__55F4C372] FOREIGN KEY([CODTPAG])
REFERENCES [dbo].[TPAGAMENTO] ([CODTPAG])
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [FK__LIQUIDACA__CODTP__55F4C372]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [CK__LIQUIDACA__CODTL__47DBAE45] CHECK (([CODTLIQ1] = 1 or [CODTLIQ1] = 0))
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [CK__LIQUIDACA__CODTL__47DBAE45]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [CK__LIQUIDACA__PAGEF__4BAC3F29] CHECK (([PAGEFECT] = 1 or [PAGEFECT] = 0))
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [CK__LIQUIDACA__PAGEF__4BAC3F29]
GO
ALTER TABLE [dbo].[LIQUIDACAO] WITH NOCHECK ADD CONSTRAINT [CK__LIQUIDACA__TIPOD__4CA06362] CHECK (([TIPODLI] = 1 or [TIPODLI] = 0))
GO
ALTER TABLE [dbo].[LIQUIDACAO] CHECK CONSTRAINT [CK__LIQUIDACA__TIPOD__4CA06362]


thank you
JamieX
JamieX
Mr or Mrs. 500
Mr or Mrs. 500 (511 reputation)Mr or Mrs. 500 (511 reputation)Mr or Mrs. 500 (511 reputation)Mr or Mrs. 500 (511 reputation)Mr or Mrs. 500 (511 reputation)Mr or Mrs. 500 (511 reputation)Mr or Mrs. 500 (511 reputation)Mr or Mrs. 500 (511 reputation)

Group: General Forum Members
Points: 511 Visits: 437
it's your order by, your are referencing an alias.
change it to "ORDER BY 5 DESC" instead of "ORDER BY NOTA.CODLIQ DESC"
river1
river1
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1762 Visits: 1366
but why does it funtion in SQL Server 2000 and don't work in 2005?
I don't understand why chande from nota..... to 5

Where is the number 5 in my table definition?

thank you.
Ken McKelvey
Ken McKelvey
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1671 Visits: 7894
I suspect SQL2005 does better syntax checking.

Your derived table, NOTA, only returns the columns SOMA and NUMDU. so

ORDER BY NOTA.CODLIQ DESC

does not make sense.

SQL2000 must try to find any column called CODLIQ while SQL2005 throws the syntax error.

As ORDER BY 5 DESC will be depreciated in future versions of TSQL, I would use:

ORDER BY CODLIQ DESC

ps ORDER BY 5 means order by the fifth column in the result set.
river1
river1
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1762 Visits: 1366
ok, thank you very mutch.

I have other question related to the same problem.

I now can run the query, but in SQL Server 2000 this query executes in 2 minutes.

When i run the query in SQL server 2005 the query starts executing , but it don't stops.

It is traing to execute during several time 40 minutes and nothing yet (no results).

Can you help pelase?

thank you
JamieX
JamieX
Mr or Mrs. 500
Mr or Mrs. 500 (511 reputation)Mr or Mrs. 500 (511 reputation)Mr or Mrs. 500 (511 reputation)Mr or Mrs. 500 (511 reputation)Mr or Mrs. 500 (511 reputation)Mr or Mrs. 500 (511 reputation)Mr or Mrs. 500 (511 reputation)Mr or Mrs. 500 (511 reputation)

Group: General Forum Members
Points: 511 Visits: 437
As ORDER BY 5 DESC will be depreciated in future versions of TSQL, I would use

Didn't know this. Good to know.

ORDER BY CODLIQ DESC

For some reason I was thinking you had to use the non aliased part of the column (which is why I did 5). This makes more sense. Don't do what I said Smile
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search