إنتقال للمحتوى

  • تسجيل الدخول عبر الفيس بوك تسجيل الدخول عبر تويتر Log In with LinkedIn Log In with Google      تسجيل دخول    
  • إنشاء حساب

صورة
- - - - -

ما هو الخطا


1 رد (ردود) على هذا الموضوع

#1 ramibn1

ramibn1

    عضو

  • الأعضــاء
  • 2 مشاركة

تاريخ المشاركة 09 April 2007 - 10:51 PM

الرجاء ايضاح لماذا لايضيف البيانات الى الجدول
وشكرا


CREATE PROCEDURE [dbo].[SP_GM_GeographyByZone] AS

declare @sqlstr as varchar(8000)
DECLARE @RB AS VARCHAR(8000)
DECLARE @RB1 AS VARCHAR(8000)
DECLARE @Year AS INT
if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'[dbo].[GM_GeographyByZone]') and type = 'U')
BEGIN transaction
TRUNCATE TABLE dbo.GM_GeographyByZone
DROP TABLE dbo.GM_GeographyByZone
commit

if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'[dbo].[GM_GeographyByZone]') and type = 'U')

BEGIN
-- DECLARE @Year AS INT
SET @Year=year(getdate())
DECLARE @tbl varchar(8000)
SET @tbl = 'CREATE TABLE [dbo].[GM_GeographyByZone] (
[gmcustomeManufacturername_vc] [varchar] (50) NULL,
[makedescription_vc] [varchar] (50) NULL,
[' + convert(varchar(4),@year-6) + '][varchar] (4) NULL,
[' + convert(varchar(4),@year-5) + '][varchar] (4) NULL,
[' + convert(varchar(4),@year-4) + '][varchar] (4) NULL,
[' + convert(varchar(4),@year-3) + '][varchar] (4) NULL,
[' + convert(varchar(4),@year-2) + '][varchar] (4) NULL,
[' + convert(varchar(4),@year-1) + '][varchar] (4) NULL
) ON [PRIMARY]'
exec(@tbl)
END
DECLARE @year int
SET @Year=year(getdate())
declare @RB varchar(8000)
SET @RB = 'INSERT INTO [dbo].[GM_GeographyByZone](
[gmcustomeManufacturername_vc] ,
[makedescription_vc] ,
[' + convert(varchar(4),@year-6) + '],
[' + convert(varchar(4),@year-5) + '],
[' + convert(varchar(4),@year-4) + '],
[' + convert(varchar(4),@year-3) + '],
[' + convert(varchar(4),@year-2) + '],
[' + convert(varchar(4),@year-1) + ']
)'
exec(@RB)

-- DECLARE @YEAR as INT
SET @Year=year(getdate())
declare @sqlstr varchar(8000)

SET @sqlstr = 'SELECT distinct C.makedescription_vc,C.gmcustomemanufacturername_vc, (select isnull(sum(vehicleCount_in),0)
gmcustomtypecode_vc from dbo.GM_TEMP_VehicleCountByDA b
inner join dbo.GMSQLDBDomesticGeographyData a
on a.PK_DA_vc=b.PK_DA_vc
where reportyear_in=' + convert(varchar(4),@year-6 ) + '
and ZoneName_vc=''ONTARIO''
and b.makedescription_vc=C.makedescription_vc
and gmprimarycode_vc=''R''
and gmcustomtypecode_vc = ''C'')
,(select isnull(sum(vehicleCount_in),0)
gmcustomtypecode_vc from dbo.GM_TEMP_VehicleCountByDA b
inner join dbo.GMSQLDBDomesticGeographyData a
on a.PK_DA_vc=b.PK_DA_vc
where reportyear_in=' + convert(varchar(4),@year-5 ) + '
and ZoneName_vc=''ONTARIO''
and b.makedescription_vc=C.makedescription_vc
and gmprimarycode_vc=''R''
and gmcustomtypecode_vc = ''C'')
,(select isnull(sum(vehicleCount_in),0)
gmcustomtypecode_vc from dbo.GM_TEMP_VehicleCountByDA b
inner join dbo.GMSQLDBDomesticGeographyData a
on a.PK_DA_vc=b.PK_DA_vc
where reportyear_in=' + convert(varchar(4),@year-4 ) + '
and ZoneName_vc=''ONTARIO''
and b.makedescription_vc=C.makedescription_vc
and gmprimarycode_vc=''R''
and gmcustomtypecode_vc = ''C'')
,(select isnull(sum(vehicleCount_in),0)
gmcustomtypecode_vc from dbo.GM_TEMP_VehicleCountByDA b
inner join dbo.GMSQLDBDomesticGeographyData a
on a.PK_DA_vc=b.PK_DA_vc
where reportyear_in=' + convert(varchar(4),@year-3 ) + '
and ZoneName_vc=''ONTARIO''
and b.makedescription_vc=C.makedescription_vc
and gmprimarycode_vc=''R''
and gmcustomtypecode_vc = ''C'')
,(select isnull(sum(vehicleCount_in),0)
gmcustomtypecode_vc from dbo.GM_TEMP_VehicleCountByDA b
inner join dbo.GMSQLDBDomesticGeographyData a
on a.PK_DA_vc=b.PK_DA_vc
where reportyear_in=' + convert(varchar(4),@year-2 ) + '
and ZoneName_vc=''ONTARIO''
and b.makedescription_vc=C.makedescription_vc
and gmprimarycode_vc=''R''
and gmcustomtypecode_vc = ''C'')
,(select isnull(sum(vehicleCount_in),0)
gmcustomtypecode_vc from dbo.GM_TEMP_VehicleCountByDA b
inner join dbo.GMSQLDBDomesticGeographyData a
on a.PK_DA_vc=b.PK_DA_vc
where reportyear_in=' + convert(varchar(4),@year-1 ) + '
and ZoneName_vc=''ONTARIO''
and b.makedescription_vc=C.makedescription_vc
and gmprimarycode_vc=''R''
and gmcustomtypecode_vc = ''C'')
from dbo.GM_TEMP_VehicleCountByDA C
order by C.makedescription_vc,C.gmcustomemanufacturername_vc'

exec(@sqlstr)

go



#2 hanyfreedom

hanyfreedom

    مشرف سابق وعضو مميز

  • المجموعة الماسية
  • 1,481 مشاركة
  • البـلـد: Country Flag
  • الاهتمامات:Chess , Sudoku

تاريخ المشاركة 23 April 2007 - 07:17 PM

?from what source you come by that