Three things:
- Your title is not descriptive (Sql left function) and therefore does not meet the forum rules.
- We can't do anything with JPG files. Post a sample Excel worksheet so others can follow
- Could you be more descriptive as your explanation isn't clear?
Please find attached excel file called logic 2
Go to the rawdata sheet, and the yellow highlighted column is a formula, i am trying to replicate this formula but in sql
In sql these are the two, tables where i need to pull the following data
PHP Code:
SELECT TOP 1000 [ID] ,[PCA] ,[Area] ,[Field_Seller_Less_1M] ,[Field_Seller_More_1M] ,[ASM] ,[RM] FROM [FDMS].[dbo].[Geo_PCA_Sellers]
Select[FDMSAccountNo], [HO], [RM_Sales_Band], [RM_Code], [Post_Code], [MCC_Code] FROM [FDMS].[dbo].[Dim_Outlet] where [RM_Sales_Band]in ('2M to 4m','4m +') and [HO] = 'Y' and rm_code = 'na' And ISO_Account = 'N' and FDMSAccountNo not in ( select [TA_MID] from fdms_partnerreporting.tmp.trade_assocations)
Which is running fine, however i need [RM] FROM [FDMS].[dbo].[Geo_PCA_Sellers]brought accross so i can link the Rm field to the postcode field on the FROM [FDMS].[dbo].[Dim_Outlet]
The only problem as mentioned in the begining post is that some postcodes have one Character and others have two
Last edited by Cutter; 08-02-2012 at 08:39 AM.
Reason: Added code tags
SELECT sub.*, rm FROM (SELECT[fdmsaccountno], [ho], [rm_sales_band], [rm_code], [post_code], CASE WHEN Isnumeric(RIGHT(LEFT(post_code, 2), 1)) = '0' THEN LEFT(post_code, 2) ELSE LEFT(post_code, 1) END AS 'sPostcode', [mcc_code] FROM [FDMS].[dbo].[dim_outlet] WHERE [rm_sales_band]IN ( '2M to 4m', '4m +' ) AND [ho] = 'Y' AND rm_code = 'na' AND iso_account = 'N' AND fdmsaccountno NOT IN (SELECT [ta_mid] FROM fdms_partnerreporting.tmp.trade_assocations)) Sub INNER JOIN [geo_pca_sellers] ON [pca] = spostcode
SELECT [fdmsaccountno], [ho], [rm_sales_band], [rm_code], [post_code], CASE WHEN [rm_sales_band] = '2M to 4m' THEN 'Test' ELSE [rm] END AS [RM], [mcc_code], FROM (SELECT sub.*, rm FROM (SELECT[fdmsaccountno], [ho], [rm_sales_band], [rm_code], [post_code], CASE WHEN Isnumeric(RIGHT(LEFT(post_code, 2), 1)) = '0' THEN LEFT(post_code, 2) ELSE LEFT(post_code, 1) END AS 'sPostcode', [mcc_code] FROM [FDMS].[dbo].[dim_outlet] WHERE [rm_sales_band]IN ( '2M to 4m', '4m +' ) AND [ho] = 'Y' AND rm_code = 'na' AND iso_account = 'N' AND fdmsaccountno NOT IN (SELECT [ta_mid] FROM fdms_partnerreporting.tmp.trade_assocations)) Sub INNER JOIN [geo_pca_sellers] ON [pca] = spostcode)
I have changed the forumla to (see below) and it seems to be running perfectly fine now . Thank you for your support .
Regards
D
PHP Code:
SELECT sub.*, case when rm_sales_band = '2M to 4M' then 'Kirsty' else RM end as rm into #rmtmp FROM (SELECT[fdmsaccountno], [ho], [rm_sales_band], [rm_code], [post_code], CASE WHEN Isnumeric(RIGHT(LEFT(post_code, 2), 1)) = '0' THEN LEFT(post_code, 2) ELSE LEFT(post_code, 1) END AS 'sPostcode', [mcc_code] FROM [FDMS].[dbo].[dim_outlet] WHERE [rm_sales_band]IN ( '2M to 4m', '4m +' ) AND [ho] = 'Y' AND rm_code = 'na' AND iso_account = 'N' AND fdmsaccountno NOT IN (SELECT [ta_mid] FROM fdms_partnerreporting.tmp.trade_assocations)) Sub INNER JOIN [geo_pca_sellers] ON [pca] = spostcode
Last edited by Cutter; 08-02-2012 at 04:46 PM.
Reason: Added code tags
Bookmarks