Here's part of my code for my Access query:
SELECT [Enter Month 1 - 12] AS ["Month"], Sum(IIf([ProductName] Like 'FHA30*',1,0)) AS ["FHA 30"]
FROM Calculations2
WHERE (((Month([LockDate]))=[enter month 1 - 12]));
It works fine, but I'm wanting it to return the name of the month in the first column instead of the number that the user inputs. I have another table that simply has a column with the month number and a column with the month name so I thought I might be able to have a second select statment with somewhere with in the SELECT [Enter Month 1 - 12] AS ["Month"], part, but I don't know how to do that. I'm real slow when it comes to coding so any help is appreciated.I did something similar but it was to return the day name, this might be of some help:
SET SERVEROUTPUT ON;
DECLARE
v_date VARCHAR2 (15);
BEGIN
SELECT TO_CHAR(sysdate, 'day')
INTO v_date
FROM dual;
DBMS_OUTPUT.PUT_LINE('The Day Today Is: '|| v_date);
END;
.|||If I understand your code, that will return the system date. In my query, the user inputs what month they want the query to run on by inputting the month number, like 1 for January. Right now, my first SELECT statement returns whatever number they input in the first column just so when it returns the query you can use that if you put the qurey results in excel or something. I just want it to convert that number into the name January. I hope I'm explaining it correctly.
Showing posts with label queryselect. Show all posts
Showing posts with label queryselect. Show all posts
Friday, February 24, 2012
Access query conversion
I have this query:
SELECT Trim(Left([Display Name],InStr([Display Name],",")-1))+Trim(Mid([Display Name],InStr([Display Name],",")+2,1)) AS UserName, dbo_Employee.[Display Name]
FROM dbo_Employee;
Works good in access, but when trying to put it un sql server, it comes up with errors.
I know mid is substring, I just don't know what trim and instr are in mssql.
SELECT Trim(Left([Display Name],InStr([Display Name],",")-1))+Trim(Mid([Display Name],InStr([Display Name],",")+2,1)) AS UserName, dbo_Employee.[Display Name]
FROM dbo_Employee;
Works good in access, but when trying to put it un sql server, it comes up with errors.
I know mid is substring, I just don't know what trim and instr are in mssql.
Any ideas?TRIM->LTRIM and RTRIM
MID->SUBSTRING
INSTR->CHARINDEX
All these functions are documented in SQL Server Books Online.|||Thanks for the quick response. Where can I find SQL Server Books Online?|||http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
It is already installed if you have SQL Server client installed.
Subscribe to:
Posts (Atom)