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 |
|
BrOkEn_iCe
Starting Member
25 Posts |
Posted - 2010-04-29 : 04:26:04
|
i need some help i convert this to sql and i have some proplem in mid and substring and i don't whycreate view q_w_clctasSELECT dbo.w_collect.comp_id, dbo.ctrl.comp_name, RTrim(LTrim(STR(dbo.w_collect.ID))) AS inv_no, dbo.w_collect.BILLINGRUN_ID, dbo.w_collect.ISSUE_MONTH, dbo.w_collect.ISSUE_YEAR, dbo.w_collect.NO_OF_MONTH, dbo.w_collect.SECTION_CODE, dbo.locations.location_name AS section_name, dbo.w_collect.BRANCH_CODE, locations_1.location_name AS branch_name, dbo.w_collect.AREA_CODE, locations_2.location_name AS area_name, Val(substring(rtrim(lTrim(dbo.w_collect.location))), 1, 7) AS lvl4, Val(substring(rtrim(lTrim(dbo.w_collect.location)), 1, 10)) AS lvl5, Val(Mid(rtrim(lTrim(dbo.w_collect.location)), 1, 14)) AS lvl6, dbo.w_collect.CUSTOMER_ACCOUNT_ID, dbo.activities.activity_code, dbo.activities.activity_name, dbo.w_collect.FILE_NO, dbo.w_collect.CUSTOMER_NAME, dbo.w_collect.CUSTOMER_ADDRESS, dbo.w_collect.METER_STATUS_CODE, dbo.meter_status.status_name, dbo.w_collect.CURRENT_READING - dbo.w_collect.PREVIOUS_READING AS qty, dbo.w_collect.USAGE, dbo.w_collect.USAGE_VALUE, dbo.w_collect.SANITARY, dbo.w_collect.MAINTENANCE, dbo.w_collect.REVENUE_STAMP, dbo.w_collect.CONTRACT_STAMP, dbo.w_collect.RECEIPT_STAMP, dbo.w_collect.INSTALLMENT, dbo.w_collect.AMOUNT_DUE, dbo.w_collect.TOTAL_DUE, dbo.w_collect.PAY_STATUS_CODE, dbo.w_collect.CAL_METHOD_CODE, dbo.w_collect.REVIEWED, dbo.w_collect.ACCOUNT_STATUS_CODE, dbo.w_collect.PAY_DATE, dbo.w_collect.NO_OF_UNITS, dbo.w_collect.AVG_USG, dbo.w_collect.SANITARY_STATUS_CODE, dbo.sewer_status.sewer_descr, dbo.w_collect.READER_CODE, dbo.w_collect.COLLECTOR_CODE, dbo.w_collect.ADD_VAL, dbo.w_collect.DEDUCT_VAL, dbo.w_collect.NO_OF_ROOM, dbo.w_collect.GOV_STAMP, dbo.w_collect.INSTALLMENT_ID, dbo.w_collect.SANITAX, dbo.w_collect.PAY_TYPE, dbo.w_collect.METER_SIZE_CODE, dbo.meter_size.size_name, dbo.w_collect.ISCALC, dbo.w_collect.pay_time, dbo.w_collect.distribution_date, dbo.w_collect.other_val, dbo.w_collect.clean_val, dbo.w_collect.stamp_date, dbo.w_collect.stamp_time, dbo.w_collect.stamp_user, dbo.w_collect.geha_code, dbo.w_collect.start_date, dbo.w_collect.end_date, dbo.w_collect.start_collector, dbo.w_collect.end_collector, dbo.w_collect.tafket, dbo.w_collect.location, locations_3.location_name, dbo.w_collect.METER_MAX, dbo.w_collect.CURRENT_READING, dbo.w_collect.PREVIOUS_READING, Int(dbo.w_collect.geha_code / 1000) AS geha_main, dbo.w_collect.inv_date, dbo.w_collect.BUILDing_no, dbo.w_collect.zone_code, locations_4.location_name AS zone_name, dbo.w_collect.block_code, locations_5.location_name AS block_name, Int(dbo.w_collect.CUSTOMER_ACCOUNT_ID / 100) AS main_act, Int(dbo.w_collect.CUSTOMER_ACCOUNT_ID / 10000) AS cust_type, dbo.w_collect.ID, dbo.w_collect.req_qty, dbo.w_collect.req_valFROM dbo.w_collect LEFT OUTER JOIN dbo.ctrl ON dbo.w_collect.comp_id = dbo.ctrl.comp_id LEFT OUTER JOIN dbo.locations ON dbo.w_collect.SECTION_CODE = dbo.locations.location_code LEFT OUTER JOIN dbo.locations AS locations_1 ON dbo.w_collect.BRANCH_CODE = locations_1.location_code LEFT OUTER JOIN dbo.locations AS locations_2 ON dbo.w_collect.AREA_CODE = locations_2.location_code LEFT OUTER JOIN dbo.locations AS locations_3 ON dbo.w_collect.location = locations_3.location_code LEFT OUTER JOIN dbo.locations AS locations_4 ON dbo.w_collect.zone_code = locations_4.location_code LEFT OUTER JOIN dbo.locations AS locations_5 ON dbo.w_collect.block_code = locations_5.location_code LEFT OUTER JOIN dbo.activities ON dbo.w_collect.CUSTOMER_ACCOUNT_ID = dbo.activities.activity_code LEFT OUTER JOIN dbo.meter_status ON dbo.w_collect.METER_STATUS_CODE = dbo.meter_status.status_code LEFT OUTER JOIN dbo.meter_size ON dbo.w_collect.METER_SIZE_CODE = dbo.meter_size.size_code LEFT OUTER JOIN dbo.sewer_status ON dbo.w_collect.SANITARY_STATUS_CODE = dbo.sewer_status.sewer_type and thx |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-04-29 : 04:35:58
|
| I have changed the function to SQL equallant..The statement is now getting compiled in SQL..SELECT dbo.w_collect.comp_id, dbo.ctrl.comp_name, RTrim(LTrim(STR(dbo.w_collect.ID))) AS inv_no, dbo.w_collect.BILLINGRUN_ID, dbo.w_collect.ISSUE_MONTH, dbo.w_collect.ISSUE_YEAR, dbo.w_collect.NO_OF_MONTH, dbo.w_collect.SECTION_CODE, dbo.locations.location_name AS section_name, dbo.w_collect.BRANCH_CODE, locations_1.location_name AS branch_name, dbo.w_collect.AREA_CODE, locations_2.location_name AS area_name, substring(rtrim(lTrim(dbo.w_collect.location)), 1, 7) AS lvl4, substring(rtrim(lTrim(dbo.w_collect.location)), 1, 10) AS lvl5, substring(rtrim(lTrim(dbo.w_collect.location)), 1, 14) AS lvl6, dbo.w_collect.CUSTOMER_ACCOUNT_ID, dbo.activities.activity_code, dbo.activities.activity_name, dbo.w_collect.FILE_NO, dbo.w_collect.CUSTOMER_NAME, dbo.w_collect.CUSTOMER_ADDRESS, dbo.w_collect.METER_STATUS_CODE, dbo.meter_status.status_name, dbo.w_collect.CURRENT_READING - dbo.w_collect.PREVIOUS_READING AS qty, dbo.w_collect.USAGE, dbo.w_collect.USAGE_VALUE, dbo.w_collect.SANITARY, dbo.w_collect.MAINTENANCE, dbo.w_collect.REVENUE_STAMP, dbo.w_collect.CONTRACT_STAMP, dbo.w_collect.RECEIPT_STAMP, dbo.w_collect.INSTALLMENT, dbo.w_collect.AMOUNT_DUE, dbo.w_collect.TOTAL_DUE, dbo.w_collect.PAY_STATUS_CODE, dbo.w_collect.CAL_METHOD_CODE, dbo.w_collect.REVIEWED, dbo.w_collect.ACCOUNT_STATUS_CODE, dbo.w_collect.PAY_DATE, dbo.w_collect.NO_OF_UNITS, dbo.w_collect.AVG_USG, dbo.w_collect.SANITARY_STATUS_CODE, dbo.sewer_status.sewer_descr, dbo.w_collect.READER_CODE, dbo.w_collect.COLLECTOR_CODE, dbo.w_collect.ADD_VAL, dbo.w_collect.DEDUCT_VAL, dbo.w_collect.NO_OF_ROOM, dbo.w_collect.GOV_STAMP, dbo.w_collect.INSTALLMENT_ID, dbo.w_collect.SANITAX, dbo.w_collect.PAY_TYPE, dbo.w_collect.METER_SIZE_CODE, dbo.meter_size.size_name, dbo.w_collect.ISCALC, dbo.w_collect.pay_time, dbo.w_collect.distribution_date, dbo.w_collect.other_val, dbo.w_collect.clean_val, dbo.w_collect.stamp_date, dbo.w_collect.stamp_time, dbo.w_collect.stamp_user, dbo.w_collect.geha_code, dbo.w_collect.start_date, dbo.w_collect.end_date, dbo.w_collect.start_collector, dbo.w_collect.end_collector, dbo.w_collect.tafket, dbo.w_collect.location, locations_3.location_name, dbo.w_collect.METER_MAX, dbo.w_collect.CURRENT_READING, dbo.w_collect.PREVIOUS_READING, Cast((dbo.w_collect.geha_code / 1000) as Int) AS geha_main, dbo.w_collect.inv_date, dbo.w_collect.BUILDing_no, dbo.w_collect.zone_code, locations_4.location_name AS zone_name, dbo.w_collect.block_code, locations_5.location_name AS block_name, Cast((dbo.w_collect.CUSTOMER_ACCOUNT_ID / 100) as Int) AS main_act, Cast((dbo.w_collect.CUSTOMER_ACCOUNT_ID / 10000) as Int) AS cust_type, dbo.w_collect.ID, dbo.w_collect.req_qty, dbo.w_collect.req_valFROM dbo.w_collect LEFT OUTER JOIN dbo.ctrl ON dbo.w_collect.comp_id = dbo.ctrl.comp_id LEFT OUTER JOIN dbo.locations ON dbo.w_collect.SECTION_CODE = dbo.locations.location_code LEFT OUTER JOIN dbo.locations AS locations_1 ON dbo.w_collect.BRANCH_CODE = locations_1.location_code LEFT OUTER JOIN dbo.locations AS locations_2 ON dbo.w_collect.AREA_CODE = locations_2.location_code LEFT OUTER JOIN dbo.locations AS locations_3 ON dbo.w_collect.location = locations_3.location_code LEFT OUTER JOIN dbo.locations AS locations_4 ON dbo.w_collect.zone_code = locations_4.location_code LEFT OUTER JOIN dbo.locations AS locations_5 ON dbo.w_collect.block_code = locations_5.location_code LEFT OUTER JOIN dbo.activities ON dbo.w_collect.CUSTOMER_ACCOUNT_ID = dbo.activities.activity_code LEFT OUTER JOIN dbo.meter_status ON dbo.w_collect.METER_STATUS_CODE = dbo.meter_status.status_code LEFT OUTER JOIN dbo.meter_size ON dbo.w_collect.METER_SIZE_CODE = dbo.meter_size.size_code LEFT OUTER JOIN dbo.sewer_status ON dbo.w_collect.SANITARY_STATUS_CODE = dbo.sewer_status.sewer_typeRegards,BohraI am here to learn from Masters and help new bees in learning. |
 |
|
|
BrOkEn_iCe
Starting Member
25 Posts |
Posted - 2010-04-29 : 04:36:26
|
| i want any one to till me any part of the code have the error and by the way there is an error near substring and i don't know why |
 |
|
|
BrOkEn_iCe
Starting Member
25 Posts |
Posted - 2010-04-29 : 04:37:08
|
| thx i will try and till u the result |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-04-29 : 04:53:55
|
quote: Originally posted by BrOkEn_iCe i want any one to till me any part of the code have the error and by the way there is an error near substring and i don't know why
the two errors were:1. You are using Mid (Which i believe extract parts of string) function which needs to be changed to substring.2. You are using CInt (which converts the input value to integer type) which needs to be changed to Cast.3. You are using Val function which doesn't exists in SQL..Regards,BohraI am here to learn from Masters and help new bees in learning. |
 |
|
|
BrOkEn_iCe
Starting Member
25 Posts |
Posted - 2010-04-29 : 06:35:14
|
| and can i know what is the wrong with this code caz he didn't work with mecast((dbo.w_collect.CUSTOMER_ACCOUNT_ID / 100) numeric) AS main_act, |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-04-29 : 08:57:12
|
| You need to use "AS" in cast..The correct stmt is:cast((dbo.w_collect.CUSTOMER_ACCOUNT_ID / 100) AS numeric) AS main_actRegards,BohraI am here to learn from Masters and help new bees in learning. |
 |
|
|
|
|
|
|
|