Fill a dynamic table

Hanen
Member Posts: 281
Hello,
I have a dynamic table with id_client and periods, every month a column period related to the month+year is created in my table, I must fill this table with the id client and the amount per period, I've find how to creat the dynamic table but not how to insert records in my table, how can I do that
I'm working with a stored procedure.
Please any one can help me :thumbsup:
Thanks for your answers
I have a dynamic table with id_client and periods, every month a column period related to the month+year is created in my table, I must fill this table with the id client and the amount per period, I've find how to creat the dynamic table but not how to insert records in my table, how can I do that

I'm working with a stored procedure.
IdClient 200901 200902 200903 200904 C001 35 € 42 € 19 € 22 €
Please any one can help me :thumbsup:
Thanks for your answers
Regards
Hanen TALBI
Hanen TALBI
0
Comments
-
I'm working with a stored procedure.0
-
I mean that I'm using SQL Server 2005 to create and insert into my table.Regards
Hanen TALBI0 -
And this table has to be accessed through the Navision client? If so that's a bad way to do it.0
-
Yes it will be accessed from navision, it's the only way I think because I'm going to use it in my report to be exported to MS Excel for statistics.Regards
Hanen TALBI0 -
And you can't create the table in Navision with the appropriate fields, and then fill it in from SQL?
This should also be moved to the SQL forum.0 -
I can't do it in vanision it's a dynamic table it means that my fields depends with the periods...........Regards
Hanen TALBI0 -
I think you are designing in wrong way.
If it is one-time generation, then it is ok to add fields in table. But if you want to use data for reports, then think to extend Key with additional column - Period.
WTF?!?!? :-k :bug: ?Name DataType Subtype Length TableRef Record Field TableRefLast Record Field TableRefLast.setrange(TableRefLast.TableNo,50000) ; TableRefLast.findfirst ; tableref := tablereflast ; TableRef."No." := 2 ; TableRef.FieldName := 'Drugi' ; tableRef.insert ;
0 -
I want to have an Excel sheet with column for CustomerId, periods from 200905 until 200909 and each month a column is added like 200910 at the end of the month filled with the amoujnt of each period per customer.
I'm using stored procedure, to create my dynamic table to be exported, everything is perfect but only the insert into didn't work, I can't fill itRegards
Hanen TALBI0 -
I can't do it in vanision it's a dynamic table it means that my fields depends with the periods...........
but if you're doing it in SQL it's your choice.
could you paste your stored procedure which inserts the records? Then it would be much easier to help you0 -
Thanks
I did it this my procedure statement:
DECLARE @weeks_ordered TABLE (num VARCHAR(7)) DECLARE @weeks TABLE (wk VARCHAR(10)) --DECLARE @DATE DATETIME DECLARE @cols NVARCHAR(3000) DECLARE @INT VARCHAR(1000) DECLARE @col_pv VARCHAR(2000) DECLARE @query VARCHAR(3000) DECLARE @debut as smalldatetime DECLARE @fin as smalldatetime SET @debut='01/01/2009' SET @fin='01/12/2009' /*****************Periods************************/ SET @INT = '200901' --SET @DATE = GETDATE() WHILE @INT <= cast(CONVERT(char(6),@fin, 112)as NVARCHAR(100)) BEGIN SET @INT = cast(CONVERT(char(6),@debut, 112)as NVARCHAR(100)) INSERT INTO @weeks VALUES (@INT) set @debut=DATEADD(month,1,@debut) END /*********************************************************/ SELECT @col_pv = STUFF(( SELECT '],[p' + p.wk FROM @weeks AS p FOR XML PATH('') ), 1, 12, '') + ']' SELECT @cols = STUFF(( SELECT '],[p' + p.wk FROM @weeks AS p FOR XML PATH('') ), 1, 12, '') + ']' IF OBJECT_ID('tempdb.dbo.#detail') IS not null DROP TABLE #detail CREATE TABLE #detail ( Client VARCHAR(20) ,Nom VARCHAR(50) ,"Id Commercial" VARCHAR(100) ,Agence Varchar (100) ,Montant DECIMAL ,Period varchar(100) ) INSERT INTO #detail SELECT hdr."Sell-to Customer No_" Client ,hdr."Bill-to Name" Nom ,cast( commercial."Name" as varchar(100)) As "Id Commercial" ,'Agence'=CASE WHEN commercial.NomCommercialDistrib='' and commercial.NTiersCommercialDistrib='' THEN commercial.NomRegroupement WHEN commercial.NTiersCommercialDistrib='' and commercial.NomCommercialDistrib<>'' THEN commercial.NomRegroupement+'#'+ commercial.NomCommercialDistrib WHEN commercial.NomCommercialDistrib='' and commercial.NTiersCommercialDistrib<>'' THEN commercial.NomRegroupement+'/'+ commercial.NTiersCommercialDistrib else commercial.NomRegroupement+'/'+ commercial.NTiersCommercialDistrib+'#'+ commercial.NomCommercialDistrib END ,hdr.Montant Montant ,'p'+cast(CONVERT(char(6),hdr."Shipment Date", 112)as NVARCHAR(100)) Period FROM dbo."CORIOLIS_V1$Sales Invoice Header" hdr INNER Join @weeks ord ON cast(CONVERT(char(6),hdr."Shipment Date", 112)as NVARCHAR(100)) = wk ,dbo."CORIOLIS_V1$Salesperson_Purchaser" commercial ,dbo.CORIOLIS_V1$Subcontract subcont WHERE subcont."Customer No_"=hdr."Sell-to Customer No_" and commercial.Code=subcont.Salesperson GROUP BY hdr."Sell-to Customer No_" ,hdr."Bill-to Name" ,subcont."Salesperson" ,commercial."Name" ,commercial.NomRegroupement ,commercial.NTiersCommercialDistrib ,commercial.NomCommercialDistrib ,hdr.Montant ,cast(CONVERT(char(6),hdr."Shipment Date", 112)as NVARCHAR(100)) ,wk ORDER BY Client SET @query = ' Select Client , Nom , "Id Commercial" , Agence , ' + @cols+ ' From #detail PIVOT (sum(Montant) FOR Period IN (' + @col_pv + ')) as pv Order By Client ' EXEC(@query)
thanks for everybody's help =D> :thumbsup:
Just one more question, anyone knows whow can we export Data to MS Excel 2007 from SQL Server 2005Regards
Hanen TALBI0 -
Just one more question, anyone knows whow can we export Data to MS Excel 2007 from SQL Server 2005
Thats about it...0 -
I want it to be done on the code, automatically on the stored procedure
I found how to do it but it works for a table not a dynamic temp tableRegards
Hanen TALBI0 -
Malajlo wrote:I think you are designing in wrong way.
If it is one-time generation, then it is ok to add fields in table. But if you want to use data for reports, then think to extend Key with additional column - Period.
WTF?!?!? :-k :bug: ?Name DataType Subtype Length TableRef Record Field TableRefLast Record Field TableRefLast.setrange(TableRefLast.TableNo,50000) ; TableRefLast.findfirst ; tableref := tablereflast ; TableRef."No." := 2 ; TableRef.FieldName := 'Drugi' ; tableRef.insert ;
not sure tu understand this post...what are you trying to achieve?inserting a field from code?you can't do it0 -
It can be done. I tried and it works.0
-
Really????
Can you tell me how?????Regards
Hanen TALBI0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions