Click to See Complete Forum and Search --> : SQL Server 2005 - Using constant for cell


chrscote
05-29-2009, 11:34 AM
I am trying to create a view that will be used in a crosstab query later. In the first view, I would like to include a constant field so that when I go to the crosstab query, this constant field will show up only for those items that it should.
For example, in the first view, if the user enters in a value of 4, the view gives me 10 records. Then, if the user enters 10, I get 17 records (the original 10 plus another 7). So, what I want is a constant in the record that will distinguish the values when I do the crosstab query, I want to be able to show that only 10 are X'ed under the column for the value 4 and 17 are X'ed under the column for the value 10.
So, how do I enter a constant value in SQL Server? Is this even possible?
I have attached a graphic of the type of table I'd like to end up with. Notice in the table that the Xes are used to tell the user which rack uses the associated column.

Chris

TheBearMay
05-29-2009, 11:53 AM
Should be able do something like:

Select "ConstantValue" columnName1 columName2 from tableName....

chrscote
05-29-2009, 12:18 PM
I've tried, but I keep getting an error saying "Invalid column name 'X'".

TheBearMay
05-29-2009, 02:22 PM
How about:

Select "ConstantValue" as "Constant", columnName1, columName2 from tableName....