Home > Archive > Microsoft SQL Server forum > December 2005 > Simple SQl question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Simple SQl question
Erich93063

2005-12-29, 8:24 pm

I am trying to create a SQL statement that returns values from fields
in the database but I also need to return values that are NOT in the
database but hard coded int he SQL statement. The values along with the
names of the fields will be hardcoded into the SQL statement. I'm not
sure if this can be done.

It will be something like this:

SELECT vchrFirstName,
vchrLastName,
'hardcoded value' AS myField
FROM tblCustomer

The above statement does NOT work. It throws an error, but that is what
I am trying to do. Bascially I want the query to return the values for
vchrFirstName and vchrLastName which are in the database, but I also
want the field called "myField" to be returned in the recordset with
the value of "hardcoded value" for every record returned. I hope this
made sense and can be done. THANKS!

Rob

2005-12-29, 8:24 pm

Erich93063 wrote:
> I am trying to create a SQL statement that returns values from fields
> in the database but I also need to return values that are NOT in the
> database but hard coded int he SQL statement. The values along with the
> names of the fields will be hardcoded into the SQL statement. I'm not
> sure if this can be done.
>
> It will be something like this:
>
> SELECT vchrFirstName,
> vchrLastName,
> 'hardcoded value' AS myField
> FROM tblCustomer
>
> The above statement does NOT work. It throws an error, but that is what
> I am trying to do. Bascially I want the query to return the values for
> vchrFirstName and vchrLastName which are in the database, but I also
> want the field called "myField" to be returned in the recordset with
> the value of "hardcoded value" for every record returned. I hope this
> made sense and can be done. THANKS!
>


Yes, it can be done, and your query should work. What's the error
you're getting?
Erich93063

2005-12-29, 8:24 pm

OK, I must have been doing somethign else wrong, because now it's
working. It's working the way I did it in my post. Not sure what I did
wring before. hmmm THANKS

John Bell

2005-12-29, 8:24 pm

Hi

At a guess you have SET QUOTED_IDENTIFIER ON and you are using double
quotes?

John

"Erich93063" <erich93063@gmail.com> wrote in message
news:1135891703.009269.19170@g43g2000cwa.googlegroups.com...
> OK, I must have been doing somethign else wrong, because now it's
> working. It's working the way I did it in my post. Not sure what I did
> wring before. hmmm THANKS
>



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com