Add Comma If Next Field Is Not Null - ms-access

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]

Related

SQL INSERT with parameter as query

How can I insert parameter with value from database.
I have some field and I should insert value from this database + 1 (with plus one)
For example
myCommand.CommandText =
"INSERT INTO GAMES (GAME_NR, GAME_PLAYER_ID, GAME_NRONTABLE, GAME_ROLE_ID) " &
" VALUES (#game_nr, #game_player_id, #game_nrontable, #game_role_id)"
'Example
myCommand.Parameters.Add("#game_nr", SqlDbType.Int).Value = **"(SELECT MAX(GAME_NR) FROM GAMES)" + 1**
You don't. You make GAME_NR and auto-incremented primary key:
create table games (
game_nr int auto_increment primary key,
. . .
);
Then you do the insert as:
INSERT INTO GAMES (GAME_PLAYER_ID, GAME_NRONTABLE, GAME_ROLE_ID)
VALUES (#game_player_id, #game_nrontable, #game_role_id);
Let the database do the work.
You don't need the parameter, you can try following code.
myCommand.CommandText =
"INSERT INTO GAMES (GAME_NR, GAME_PLAYER_ID, GAME_NRONTABLE, GAME_ROLE_ID) " &
" VALUES ((SELECT MAX(GAME_NR) + 1 FROM GAMES), #game_player_id, #game_nrontable, #game_role_id)"
But it looks like a primary key of the table. If Game_Nr is pr, You should use auto-inc. identity, then you don't need this param.
It will be.
myCommand.CommandText =
"INSERT INTO GAMES (GAME_PLAYER_ID, GAME_NRONTABLE, GAME_ROLE_ID) " &
" VALUES (#game_player_id, #game_nrontable, #game_role_id)"

Insert with Select clause Nodejs query string

I have the following query:
var query2 = "INSERT INTO abonnement (type_carte,type_demande,type_abonnement,classe,date_validite,gare_depart,gare_arrivee,id_client) VALUES ('"+t_carte+"','"+t_demande+"','"+t_abonnement+"','"+classe+"','"+date_validite+"','"+g_depart+"','"+g_arrive+"','SELECT id_client from client WHERE id_client=8')";
But when I execute it I receive the following error:
mysql ERROR : Incorrect integer value : 'select id_client from client where id_client = 8 ;
FYI , id_client is a foreign key from table client.
For id_client field you have to pass out put of the select statement but not the statement itself as a 'string literal'. Remove the surrounding single quotes and just put parenthesis.
var query2 =
"INSERT INTO abonnement (type_carte, type_demande, type_abonnement
, classe, date_validite, gare_depart
, gare_arrivee, id_client)
VALUES ( '" + t_carte + "','" + t_demande + "','"
+ t_abonnement + "','" + classe + "','"
+ date_validite + "','" + g_depart + "','"
+ g_arrive
+ "', ( SELECT id_client FROM client
WHERE id_client = 8 LIMIT 1 )
)";
I have added LIMIT 1 clause, because in case if the statement returns more than a single record, your query would fail.
PS: When you already know value of id_client field, why are you using select id_client ... where id_client=8 ... statement? You can directly input '8' in place of this unnecessary statement.

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"

insert statement difficulty

this is where I am getting my info from, and when I choose the address it fills in all the info
but the problem starts when I try to add a renter to the renter table after I have deleted a renter. this table no longer shows columns with all addressIDs so I am trying to insert the AddressID as well from the property table.I hope this makes sense
I cant insert pictures yet, but here is what it looks like when i chose a property, rentals
if ( ( evt.getStateChange() == java.awt.event.ItemEvent.SELECTED ) &&
( PropertyComboBox.getSelectedIndex() != 0 ) )
{
Address = ( String ) PropertyComboBox.getSelectedItem();
try {
myResultSet = myStatement.executeQuery(
"SELECT Property.Address,Property.AddressID,Property.RentAmt, Renter.RenterID, Renter.AddressID, Renter.FirstName, Renter.LastName, Renter.CellPhone, Renter.DepositPaid,Renter.DepositAmtPaid " +
"FROM Property, Renter " +
"WHERE Property.Address = '" + Address + "'" + "AND Renter.AddressID = Property.AddressID" );
if (myResultSet.next())
{
renterID = (myResultSet.getString("Renter.RenterID"));
addressID = (myResultSet.getString("Property.AddressID"));
txtRentAmt.setText(myResultSet.getString("Property.RentAmt"));
txtShowAddressID.setText(myResultSet.getString("Property.AddressID"));
txtShowRenterID.setText(myResultSet.getString("Renter.RenterID"));
txtFirstName.setText(myResultSet.getString("Renter.FirstName"));
txtLastName.setText(myResultSet.getString("Renter.LastName"));
txtCellPhone.setText(myResultSet.getString("Renter.CellPhone"));
txtDepositPaid.setText(myResultSet.getString("Renter.DepositPaid"));
txtDepositAmtPaid.setText(myResultSet.getString("Renter.DepositAmtPaid"));
if(myResultSet.getString("Renter.DepositPaid") == ("Y"))
{
txtDepositPaid.setText("Y");
}
else
{
txtDepositPaid.setText("N");
}
}
}
can someone help me with this ? I am trying to insert a new renter
from a netbeans jform into my database. The AddressID
(PK,auto-increment ) from the property table should automatically
insert into the renter table AddressID (FK, auto-increment(so I
thought)
It will insert if I use this statement but then the addressID shows as
NULL, not the AddressID from the property table, which I need. Ive
been working on this since Saturday. UGH Please help! very simple, yet
I cannot figure it out
ls_query = "INSERT INTO Renter (FirstName,LastName,CellPhone,DepositPaid,DepositAmtPaid)"
+ " VALUES (" + addressID + ",'"
+ addFirstName + "','"
+ addLastName + "','"
+ addCellPhone + "','"
+ addDepositPaid + "',"
+ addDepositAmtPaid + ")" + " WHERE Property.AddressID = " + addressID ;
INSERT plus WHERE? i guess you need UPDATE, not INSERT http://dev.mysql.com/doc/refman/5.0/en/update.html
EDIT: it's not clear, you are mixing in insert in one table with a where in another table?, just do "INSERT ... (fields) VALUES (values)" without WHERE and specify all addressID on fields.
You need to specify AddressID in the field list.
...INTO Renter (AddressID, FirstName...
Assuming that you specify all columns in the table, you can omit the field list.
You may also be more comfortable with the INSERT ... SET syntax.

About string datatype in vb.net

I have a String variable in VB.NET and it contains a value like
"Date of 9/23/2012 Tot Sec_sale Amt = 29,22,696RM's Wise , Gunadeep=15,83,876 , Purushothaman C.S.=1,12,829 , P.madhusudhanreddy=4,63,933 , Sunil vakayil=6,31,120 , Girish Varghese=33,019 , Debarun Chakraborty=79,288 , Rajiv Varma=18,630, RM's DT Count 1,342"
In application side I am able to view this value. I stored this value in MySQL table column. That column contains a longtext datatype. But I am not able to view the full content. Not able to view the last part RM's DT Count 1,342. It shows like Rm's....
My table structure:
fld_msg longtext
fld_phone varchar(20)
fld_date date
fld_status varchar(45)
fld_type varchar(45)
fld_name varchar(50)
My VB.NET code:
Dim bh_msg As String =
"Date of " + Convert.ToDateTime(txt1.Text).Date +
" Tot Sec_sale Amt = " + strdmy_bh_sec_amt.ToString +
"RM's Wise " + bh_amt_frmt1.ToString + "," +
" RM's DT Count " + str_bh_dt_count.ToString
Most DB Viewer truncate long texts fields (blob, clob, ...) in order to maintain performances. But that's just debug view. The real data, and your program, should use the entire value.
Try to retrieve those values using your VB code. It should work