Divide by from selected columns - sql-server

Sorry if the question was asked before i try search but not found. I'm still new on mssql so
maybe the answer are obvious just i cant find.
My current query is:
SELECT gold_min, gold_max, gold_min_2, gold_max_2
FROM m_rdb
I want to divide the values on current columns by 20 and then update, just not sure how to do.
Any help are welcome.

Are you looking for this:
update m_rdb
set col=col/20.0

If your updating the values to same columns then
Update m_rdb SET gold_min = gold_min/20, gold_max=gold_max/20,
gold_min_2=gold_min_2/20, gold_max_2=gold_max_2/20
If your updating the values to Other columns then
Update m_rdb SET gold_min_other = gold_min/20, gold_max_other=gold_max/20,
gold_min_2_other=gold_min_2/20, gold_max_2_other=gold_max_2/20

Related

Batch edit column fields of selected rows via phpMyAdmin

I have a picture gallery (built with Coppermine) and I'm trying to backdate a bunch of pictures; to do so I know that I have to edit two columns (mtime and ctime) in the coppermine DB.
Both columns are contained in a table named 'db_pictures'.
I have already done that manually and I know it works.
Now the problem is that I have to edit approx 300-400 pictures (=300-400 rows, 1 row per picture) in the 'db_pictures' table and it would take forever to do that manually.
I thought this could be done quicky and effortlessy with the right command so I searched the site and found this; unfortunately I get a syntax error when I try to apply this command:
UPDATE db_pictures SET ctime=[new value] WHERE [old value]
What am I doing wrong? Could somebody tell me how to apply the right command, please?
Condition in WHERE clause must evaluate to a boolean value i.e. ´true´ or false, see UPDATE Syntax:
UPDATE db_pictures SET ctime=[new value] WHERE ctime=[old value]
or, as your question seems to be a bit unclear,
UPDATE db_pictures SET ctime=[new value] WHERE mtime=[old value]

laravel is there a way to get smallest or highest id

Is there a way to get the smallest and highest id in your table and check that in an if / else statement?
I already tried $user->first() and $user->last() but those did not work well.
Use the min/max functions of Eloquent.
User::max('id');
User::min('id');
This will get you the highest and User id's
User::orderBy('id', 'desc')->first()->id;
User::orderBy('id', 'asc')->first()->id;
I'm not exactly sure what you mean by "check that in an if / else statement." If you could provide a little more explanation I'd be able to help more.

last generate id manual query in cakephp

I have apply manual query in cakephp and not get last generate id
My query is this
$areas = $this->Area->query("insert into areas (Area_ID,Parent_Area_ID,Area) values ('','".$Parent_Area_ID."','".$Area_name."')");
How i get last id ?
Try this code:
$this->Area->getInsertID();
More detail here:
http://book.cakephp.org/2.0/en/models/additional-methods-and-properties.html#model-getinsertid
Try this
echo $this->Area->getLastInsertID();
If this doesn't work check out this answer from a similar question

How to set value in a field by UI?

I use three fields in Sqlserver Datavbase tables, for prevent delete records permanently by user:
IsDelete (bit)
DeletedDate (DateTime)
DeletedUserID (bigint)
I wish to set third field (DeletedUserID) by UI by some thing like this:
this.ExamdbDataSet.AcceptChanges();
DataRowView row = (DataRowView)this.BindingSource.Current;
row.BeginEdit();
row["DeletedUserID"] = User.User.Current.ID;
row.EndEdit();
this.ExamdbDataSet.AcceptChanges();
row.Delete();
and other two fields ,'IsDeleted' field and 'DeletedDate' are set automatically in table's 'After Delete Trigger'.
then commit changes to database with desire command successfuly with this code:
this.TableAdapterManager.UpdateAll(this.ExamdbDataSet);
but problem is , the 'DeletedUserID' is null in database.
and Question is : How to set 'DeletedUserID' field value by true way in UI?
I don't think it is a good way to do that. You have sliced a simple logic to separate parts, each being done in a different part of the application (UI, Trigger, ...). You set value of some field, and then DELETE the whole record! Don't expect anything else that the current situation.
You would better set all fields in UI (i.e. no trigger in this case), and change the query that loads data. For example,
Select * from table1 where IsDeleted=0
You didn't tell us anything about whether your use ASP.Net or WinForms. Give us more info.

get ids of all inserted records by last query executed in cakephp

I can find the primary key id of last inserted record as follows:
$this->Model->save($record);
$id = $this->Model->getLastInsertId();
I am looking for something like this:
$this->Model->saveAll($records);
$ids = $this->Model->getLastInsertIds();
I am inserting 100s of records, so its better to insert them all in a single query. Still its taking some seconds to execute the use case. Is there a way to get all ids of inserted records by last query?
This was asked in many forums, but there are no clear answer.
I think this might work and might be what you are looking for:
$this->Model->saveAll($records);
$id1 = $this->Model1->id();
$id2 = $this->Model2->id();
$id3 = $this->Model3->id();
...
Remember to replace model1,model2,model3 with each of the models that you are saving to.
Have you looked at the cakephp tutorial on saving your data? here is the link:
http://book.cakephp.org/view/1031/Saving-Your-Data
Hope this helps.

Resources