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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Trailing Spaces

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2012-06-25 : 11:42:58
I have a filler field that stores to sets of data.
Filler_001 field is char(42).
First 5 characters are for Cust_type
Next 15 are for item_no.


I'm doing an insert from another table. So the cust_type could be any number of characters 1 thru 5.

When I grab the cust type value and if its under 5 characters I need to add trailing spaces.

Field should look like this:
1 ITEM1
12 ITEM2
123 ITEM3
1234 ITEM4
12345ITEM5

Here is my try:
INSERT INTO oeprcfil_sql ( cd_tp, curr_cd, filler_0001,

start_dt, end_dt,
cd_prc_basis,
minimum_qty_1, prc_or_disc_1, minimum_qty_2, prc_or_disc_2,
minimum_qty_3, prc_or_disc_3, minimum_qty_4, prc_or_disc_4,
minimum_qty_5, prc_or_disc_5, minimum_qty_6, prc_or_disc_6,
minimum_qty_7, prc_or_disc_7, minimum_qty_8, prc_or_disc_8,
minimum_qty_9, prc_or_disc_9, minimum_qty_10, prc_or_disc_10,
filler_0004 )
SELECT ex.cd_tp, ' ', left(ex.cd_tp_3_cust_type&space(5),5)+ex.cd_tp_3_item_no,
ex.start_dt, ex.end_dt,
ex.cd_prc_basis,
ex.minimum_qty_1, ex.prc_or_disc_1, ex.minimum_qty_2,
ex.prc_or_disc_2, ex.minimum_qty_3, ex.prc_or_disc_3,
ex.minimum_qty_4, ex.prc_or_disc_4, ex.minimum_qty_5,
ex.prc_or_disc_5, ex.minimum_qty_6, ex.prc_or_disc_6,
ex.minimum_qty_7, ex.prc_or_disc_7, ex.minimum_qty_8,
ex.prc_or_disc_8, ex.minimum_qty_9, ex.prc_or_disc_9,
ex.minimum_qty_10, ex.prc_or_disc_10,
'Added on ' + CONVERT(VARCHAR(10), GETDATE(), 110) AS [MM-DD-YYYY]
FROM PriceDataBase...PriceCode3Send$ ex
LEFT OUTER JOIN oeprcfil_sql c
ON c.cd_tp = ex.cd_tp
--AND c.curr_cd = ex.curr_cd
AND left(c.filler_0001,5) = ex.cd_tp_3_cust_type
AND substring(c.filler_0001,6,15) = ex.cd_tp_3_item_no
AND c.start_dt = ex.start_dt
AND c.end_dt = ex.end_dt
WHERE c.cd_tp IS NULL
and c.curr_cd is NULL
and left(c.filler_0001,5) is NULL
and substring(c.filler_0001,6,15) is NULL
and c.start_dt is NULL
and c.end_dt is NULL



I get the following error when trying to run.
The data types nvarchar and varchar are incompatible in the boolean AND operator.

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-06-25 : 11:55:57
I would expect to see an & to give that error.

Hah - found it
left(ex.cd_tp_3_cust_type&space(5),5)+ex.cd_tp_3_item_no,

change to
left(ex.cd_tp_3_cust_type + space(5),5)+ex.cd_tp_3_item_no,


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -