Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL SELECT column puzzler
Message
From
11/03/2005 18:10:57
 
General information
Forum:
Visual FoxPro
Category:
Client/server
Environment versions
Database:
MS SQL Server
Miscellaneous
Thread ID:
00994995
Message ID:
00995066
Views:
20
I know you want a generic solution but.........

does the problem field have the same name in each table? If so you might be able to piece together some older stuff using APPEND FROM. For example
lnCurWA = SELECT()
SELECT (lcBaseTable)
COPY TO temptable
SELECT 0
USE temptable
REPLACE ALL badField WITH RIGHT(badfield,2)
USE
SELECT (lcArchTable)
APPEND FROM temptable
DELETE FILE temptable.*
SELECT (lnCurWA)
>I am having trouble satisfying an unusual requirement which stems from poor data design (not mine!). What I need to do is copy records for the current period to an archive table. The two tables have identical structures, EXCEPT for one field which is char(3) in the base table and char(2) in the archive table. The insert is done as follows:
>
>INSERT INTO ?lcArchTable SELECT * FROM ?lcBaseTable
>
>This fails with the error message "String or binary data would be truncated." This is because it is trying to populate a 2 character column from a 3 character column. How can I get around this? I have tried doing an ALTER TABLE before the INSERT, to widen the column in the archive table to 3 characters, then altering it back to 2 characters afterwards. But the second ALTER fails with the same error message. (And even if it did work, I want the rightmost 2 characters, not the leftmost).
>
>I know I could use an explicit column list but there are actually several tables that have this same problem. It is all in a generic routine. I don't want to hard code columns of these particular tables and have to change code every time their structure changes. I was hoping there was something like "SELECT [all columns except ThisOne], RIGHT(ThisOne,2) AS ThisOne", but can find no such beast.
>
>Any ideas? TIA!
>
>Mike
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform