SQLTeam.com | Weblogs | Forums

Sql code to use form entry as a column name to select


#1

So I am trying to use a form to define criteria for a query to execute. So far it has been working however I ran into a problem when trying to make the form combo box be the column it looks up. I have basic sql knowledge and am just learning so any help would be appreciated. My code is so far

SELECT MAX([300]) AS MAXPRESSURE
FROM [PRESSURE TEMP]
WHERE MATERIAL='WCB'

the 300 is the column name and that is where I would like it to be the form info. I have tried using
MAX([PRESSURE TEMP].[Forms]![SELECTION]![Combo0]) and it has not worked. then I tried adding ' ' and it just displays the text. If it makes a difference the form entry is using a combo box to limit user options


#2

Does the query on its own work (e.g. in SSMS)?

Or, are you looking for how to code it in your application (C#/VB)?


#3

Hi, Here is a sample code for your problems may it help yours.

SELECT *
FROM db_name_SCHEMA.COLUMNS
WHERE Table_Name = N'table_name'

This is better one than getting from "sys.columns" because it shows the DATA_TYPE directly.