Microsoft Access Data Base .. Select Query - ms-access

i am doing queries practice in Microsoft access. i want to concatenate the first name with the fax number.. the fax number is like (123)555-0103 ..
i`m doing that
select [first name] +' ''s Fax Number is' +str(fax number) as [Mariya`s Fax Number]
from employees where id =4;
but it is giving error..

That would be:
select [first name] & " ''s Fax Number is " & [fax number] as [Mariya`s Fax Number]
from employees where id =4
You should use & to concatenate
You should use '' for each single quote
You should use double quotes (") for strings.

Related

Force Short TextField To Always Be X Characters

I am attempting to use a IIF() statement in a query to update a short text field to always be 4 characters. This is my syntax, but
SELECT DISTINCT IIf(Len([User ID] = 1), "000" & [User ID], IIf(Len([User ID] = 2), "00" & [User ID], IIf(Len([User ID] = 3), "0" & [User ID], [User ID]))) AS ST
FROM _TestData;
However it seems to be appending 0's to the data regardless of length?
It could be this simple:
SELECT DISTINCT Right("000" & [User ID], 4) AS ST
FROM TestData;
If [User ID] is number, try this:
SELECT DISTINCT Format([User ID], "0000") AS ST
FROM _TestData;
Update
Missed that the field is short text. In this case
SELECT DISTINCT Format(CLng(Nz([User ID],0)), "0000") AS ST
FROM _TestData;

In Telerik radrotator(legand) date is binding as system.byte

In Telerik radrotator(legand) date is binding as system.byte:
Dim mssQL=" case when a.log_type='Schedule' then" & _
" (select case when e.schedule_type='Call Log' then cast( concat(d.user_firstname,' ',d.user_lastname,' ','Scheduled a Call On',' ',(DATE_FORMAT(e.schedule_date,'%d-%m-%Y') ) ) as char )" & _
" when e.schedule_type='Meeting' then cast(concat(d.user_firstname,' ',d.user_lastname,' ','Scheduled a Meeting On', ' ',(DATE_FORMAT(e.schedule_date,'%d-%m-%Y') )) as char )" & _
" when e.schedule_type='Mail Log' then cast (concat(d.user_firstname,' ',d.user_lastname,' ','Scheduled Mail On',' ',(DATE_FORMAT(e.schedule_date,'%d-%m-%Y'))) as char) end from crm_trn_tschedulelog e where e.log_gid=a.log_gid group by a.log_gid)"
The problem is with your CAST() and concat() functions. The concat() will give you result as system.byte when the input parameters to the function are of different types, here you are concatenating string and DATE Together. you you need to cast the Formatted Date also and remove the cast before the Concat(). Hence your query will be like the following:
concat(d.user_firstname,' ',d.user_lastname,' ','Scheduled Mail On',' ',cast (DATE_FORMAT(e.schedule_date,'%d-%m-%Y') as char)))

Add Comma If Next Field Is Not Null

I need to display data in a lastname, firstname, salutation format. However there are a few rare instances where salutation is null, so I wouldn't want to display firstname, if salutation is null. Or there (doubtful) could be a possibility that firstname is null and salutation so I wouldn't want to show lastname, , ,.
How can I in my query use a condition to only include the comma if the next field is not null?
NameWithSal: [LastName] + ", " + [FirstName] + ", " + [Salutation]
In Access, what you have will result in null if any of the fields are null. The following should provide what you specified. [LastName] & ", " + [FirstName] & ", " + [Salutation]

Inserting values starting with zero in access database

I have a field called Product_Id(type string), which has length of 7 and starting with 0. But while inserting through VBA into a table field of type text the zeros is not getting inserted.
This is the insert query:
dbs.Execute "INSERT INTO tablename (PROD_NBR)VALUES (" & prodID & ");"
I think I have fixed the error - you need to declare the value in single quotes.
The PROD_NBR is a string type and field in the table is text type, then the inserting variable should be declared inside single quotes then double quotes and between two & symbols:
dbs.Execute "INSERT INTO tablename (PROD_NBR)VALUES ('" & prodID & "');"
Responding to #Cherry's answer, the following method is less tedious than a parameterized query, aka prepared statement. prodID can safely contain quotes and other special characters.
With dbs.OpenRecordset("tablename")
.AddNew
.Fields("PROD_NBR") = prodID
.Update
End With
Regarding the "starting with zero" part of your question, do you want PROD_NBR to always be 7 characters, padded with leading 0's? Then replace prodID with:
Right("0000000" & prodID, 7)

Adding underscore and jpg to the output field

The output from my Parameter is FirstName LastName.
I want the final to be FirstName_LastName.jpg. Below is what I would do in SQL but how can I do the same in my SSRS report?
update #signatures set fullname = REPLACE(REPLACE(filename, ' ', '_'),' ','.jpg')
I tried the following but the result was FirstName LastName_.jpg.
=Format(Parameters!Signature.Value, (Parameters!Signature.Value)&"")&".jpg"
=Replace(Parameters!Signature.Value, " ", "_") & ".jpg"