Solved

How to determine the value of a field after it has been selected from a varchar field of 1 table and converted to an INT type value and inserted into another Sybase table with a field type of INT ?

Posted on 2016-11-09
2
46 Views
Last Modified: 2016-11-09
I am inserting records into a Sybase Table using
I am using a C# program to read in the records from a txt file named InputFile.txt into a Sybase table titled tableA.
One of the fields I read into tableA has a title "age" which has a datatype of varchar(3).
Let's say I read in the records as follows:

                   while ((line = file.ReadLine()) != null)
                    {
                        DataRow row = dt.NewRow();
                        row["age"] = line.Substring(45, 3);

Then I select the records from tableA insert them into another table, tableB that has a field titled "AgeDays" that is an INT type field. This is carried out as follows:

INSERT INTO tableB (
            AgeDays  )      
           SELECT
           CONVERT(INT, W.age) * 1 AS Expr4

If a record in the InputFile.txt has an Age value of '000' that is imported into the field tableA.age, what value would appear in tableB.AgeDays after the insertion statement is executed?
0
Comment
Question by:zimmer9
2 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 41881093
000 is cast to 0 . . . 0 * 1 = 0.
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 41881132
Since it is being inserted into an int field, the value will have all leading 0s stripped (000 -> 0, 001 -> 1, 010 -> 10, etc).
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now