Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
fishbait01
Starting Member
2 Posts |
Posted - 2006-01-04 : 15:07:53
|
| Environment: SQL SERVER 2000Hi,I have a DW application that requires generating different columns based on logic using the product number and a couple of other parameters. Here is an example: InputProduct Number: ABC1Product Type: 1234Division Name: ZZAOutputFamily: Hard ShellSeries: A seriesRange: +/- 5.0Category: RetailSales Type: Resale SalesThe output values are determined by hard coded logic. The logic does not contain any table reads. This data must be loaded into a 3rd party OLAP Cube using a simple SQL statement using a GROUP BY.I created a UDF receiving 4 parms and returning a nvarchar. Here is an example of the SELECT statement using this UDF:SELECT…ProdNoProdType,Division,ProdSect_fns(Division, ProdNo, ProdType , 'FAMILY') as ProdFamilyProdSect_fns(Division, ProdNo, ProdType , 'SERIES') as ProdSeriesProdSect_fns(Division, ProdNo, ProdType , 'RANGE') as ProdRangeProdSect_fns(Division, ProdNo, ProdType , 'CATEGORY') as ProdCategoryProdSect_fns(Division, ProdNo, ProdType , 'GROUPING') as ProdGroupingFROM InvoiceTableProblem:If I use a simple SQL Statement (without GROUP BY) this works fine but as soon as I have a GROUP BY, the function ProdSect_fns returns the same value for all 5 columns.Second Problem:I tried testing a workaround by adding theses 5 columns to the DW InvoiceTable and use the DW Loading Stored Procedure to populate these colums but when I added the function in the INSERT INTO or UPDATE, it returns an error: Arithmetic overflow error converting expression to data type nvarchar? Any ideas what is causing my problem? |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-01-04 : 15:31:42
|
| Problem1 :Try Select * from (SELECT…ProdNoProdType,Division,ProdSect_fns(Division, ProdNo, ProdType , 'FAMILY') as ProdFamilyProdSect_fns(Division, ProdNo, ProdType , 'SERIES') as ProdSeriesProdSect_fns(Division, ProdNo, ProdType , 'RANGE') as ProdRangeProdSect_fns(Division, ProdNo, ProdType , 'CATEGORY') as ProdCategoryProdSect_fns(Division, ProdNo, ProdType , 'GROUPING') as ProdGroupingFROM InvoiceTable ) as Qry1group by ProdNo, ProdType, Division, ProdFamily, ProdSeries, ProdRange, ..... |
 |
|
|
fishbait01
Starting Member
2 Posts |
Posted - 2006-01-04 : 15:45:00
|
| Tried your suggestion but I'm still get the same problem (same value for all 5 columns calling the UDF)There are many solutions to a problem. Your imagination is your limit! |
 |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-01-04 : 20:27:27
|
| Can u please give the function ProdSect_fns() along with some sample data in the table |
 |
|
|
|
|
|
|
|