Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL SELECT ADD A FIELD

Status
Not open for further replies.

Scott24x7

Programmer
Jul 12, 2001
2,826
JP
It is possible in the SELECT (SQL) Statement to add a field that doesn't exist in the target table?

For Instance:

SELECT FirstName, LastName, Age, Attendee(as a logical) FROM GUESTLIST INTO TABLE CONFIRMED

Where "Attendee" doesn't exist in the table "GUESTLIST" but want to add it as a logical field?
Is this possible?


Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
One caveat: Make sure the new field is wide enough to hold the required data. This doesn't apply to logical fields, dates or datetimes (which are fixed length), but it could trip you up with characters and numbers. For example:

[tt]SELECT ID, Name, 0 AS Salary FROM Employee[/tt]

This will give you a Salary field which is only one character wide. Better do this:

[tt]SELECT ID, Name, CAST(0 AS N(10,2)) AS Salary FROM Employee[/tt]

Similarly, rather than this:

[tt]SELECT ID, Name, " " AS Department FROM Employee[/tt]

do this:

[tt]SELECT ID, Name, SPACE(15) AS Department FROM Employee[/tt]


Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Wow, that's just awesome, and just totally fixed my grid control issue. :)

Best Regards,
Scott
ATS, CDCE, CTIA, CTDC

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top