Select into query, insert fails, but the table is created

I am using SQL Server 2016

I tried to the following query.

SELECT CONVERT(BIGINT, ‘A’) col1 INTO #tmp This query is obviously in error. Because it does not convert. However, the temporary table (#tmp) is created even if the query fails.

Why? I think this is by design, but I want to know.

P.S. PDW (parallel datawarehouse) does not create temporary table.

How to turn SELECT statement into a DELETE statement

I’m trying to turn this select statement into a delete statement and I’m struggling to not delete all the records in the table. Here is the select statement I’m using ->

"SELECT * FROM message_cus_board mcb where mcb.board_id IN (select mb.board_id FROM message_boards mb WHERE mb.customer_id = :customerid AND mb.universal_board = 'Y') ORDER BY mcb.created_on DESC" 

This queries all of the messages from the message_cus_board table and basically I want to delete all of the messages this would normally display except the last 15. One thing I’ve tried is taking all of those message_id’s and making an array of the most recent 15 then creating a delete statement with those id’s like so ->

"DELETE FROM message_cus_board WHERE message_id NOT IN ($  string_of_ids)" 

The only issue is that this delete query gets rid of ALL other messages, not just the ones associated with the right customer. I’m struggling to create a delete query that limits the delete to the right customer using similar logic to the select statement above. Thanks for any help!

Matrix to select most relevant security test cases to automate

I spend some quality time on studying security reports on the internet. I build from it an overview of the most relevant security risk category (Injection, session management, and so on) along with an average risk number (high, medium, low). Now I want to create a matrix that will help to select the most relevant test cases to automate.

I was thinking of having these factors:

  • Attack complexity
  • Tool availability
  • Risk value (high, medium, low)

Is this a good approach? I like to hear a second option about what to change/improve.

ACF Dynamic select values not showing data

This question makes me crazy for almost 2 weeks. I know I am not expert in WordPress, so I am seeking for help here.

I have create a href that when user click it will go to new page.

<a href="./create-class?post=<?php echo $  post->ID; ?>">Add Class2</a> 

This href post the Post id. Url display:


create-class page:

At create-class page,I am using GET method to display post id from url

$  post = $  _GET['post']; 

I have acf form in create-class page for create new post. In this form, there have dynamic select field but the select field not display any data.

 <?php      acf_form(array(           'post_id'   => 'new_post',           'field_groups' => array(150),           'post_title'  => false,           'post_content'  => false,           'new_post'    => array(                   'post_type'   => 'classes',                   'post_status' => 'publish',                   ),           'return'    => '%post_url%',           'submit_value'  => 'Submit',           //'updated_message'    => 'Course Submit!',         )); ?> 

in my function.php I create function for dynamic select:

function acf_load_t_first_name2_field_choices($  field) {     global $  post;     //$  post = $  _GET['post'];     // reset choices     $  field['choices'] = array();       // get the textarea value from options page without any formatting     $  choices = get_field('t_first_name',$  post->ID);        // loop through array and add to field 'choices'     if( is_array($  choices) ) {          foreach( $  choices as $  choice ) {              $  field['choices'][ $  choice ] = $  choice;          }      }       // return the field     return $  field;  }  add_filter('acf/load_field/name=t_first_name2', 'acf_load_t_first_name2_field_choices');  

Is there something wrong with my code?

Creating a Woocommerce custom shipping method as a select field

I’m working with thw WooCommerce plugin for WordPress. My main goal right now is to create a custom shipping method. So far I’ve managed to create this method and display the same in my billing form. The problem is that this shipping methods are checkbox by default and I want an extra funcionality: Display a select with a series of options as soon a I select this custom shipping method on the billing order form.

This next class handles the custom shipping method:

/**  * WC_Shipping_Pickup class.  *  * @class       WC_Shipping_Pickup  * @version     1.0.0  * @package     Shipping-for-WooCommerce/Classes  * @category    Class  * @author      Pickup Softwares  */ class WC_Shipping_Pickup extends WC_Shipping_Method {     public function __construct($  instance_id = 0)     {         $  this->id                    = 'pickup_method';         $  this->instance_id           = absint($  instance_id);         $  this->method_title          = __('Pickup');         $  this->method_description    = __('Método de envío: punto de pickup');         $  this->supports              = array(             'shipping-zones',             'instance-settings',         );          $  this->instance_form_fields = array(             'enabled' => array(                 'title'         => __('Habilitar/Deshabilitar'),                 'type'          => 'checkbox',                 'label'         => __('Habilitar este método de envío'),                 'default'       => 'yes',             ),             'title' => array(                 'title'         => __('Título'),                 'type'          => 'text',                 'description'   => __('Título que se visualizará en el formulario de facturación'),                 'default'       => __('Pickup'),                 'desc_tip'      => true             )         );          $  this->enabled              = $  this->get_option('enabled');         $  this->title                = $  this->get_option('title');          add_action('woocommerce_update_options_shipping_' . $  this->id, array( $  this, 'process_admin_options' ));     }      public function calculate_shipping($  package = array())     {         $  this->add_rate(array(             'id'    => $  this->id . $  this->instance_id,             'label' => $  this->title,             'cost'  => 0,         ));     }      /**      * Generate Select HTML.      *      * @param string $  key Field key.      * @param array  $  data Field data.      * @since  1.0.0      * @return string      */     public function generate_select_html()     {         $  token = null;         $  expire = null;         $  token = qk_login($  token, $  expire);          $  agencies = qk_agencies($  token);          $  field_key = $  this->get_field_key('_pickups');          $  options = [];         foreach ($  agencies as $  agency) {             $  options[$  agency->id] = $  agency->detalle;         }          $  defaults  = array(             'title'             => 'Pickups',             'disabled'          => false,             'class'             => '',             'css'               => '',             'placeholder'       => 'Seleccionar punto de recogida',             'type'              => 'text',             'desc_tip'          => false,             'description'       => '',             'custom_attributes' => array(),             'options'           => $  options,         );          $  data = wp_parse_args($  data, $  defaults);          ob_start(); ?>         <tr valign="top">             <th scope="row" class="titledesc">                 <label for="<?php echo esc_attr($  field_key); ?>"><?php echo wp_kses_post($  data['title']); ?> <?php echo $  this->get_tooltip_html($  data); // WPCS: XSS ok.?></label>             </th>             <td class="forminp">                 <fieldset>                     <legend class="screen-reader-text"><span><?php echo wp_kses_post($  data['title']); ?></span></legend>                     <select class="select <?php echo esc_attr($  data['class']); ?>" name="<?php echo esc_attr($  field_key); ?>" id="<?php echo esc_attr($  field_key); ?>" style="<?php echo esc_attr($  data['css']); ?>" <?php disabled($  data['disabled'], true); ?> <?php echo $  this->get_custom_attribute_html($  data); // WPCS: XSS ok.?>>                         <?php foreach ((array) $  data['options'] as $  option_key => $  option_value) : ?>                             <option value="<?php echo esc_attr($  option_key); ?>" <?php selected((string) $  option_key, esc_attr($  this->get_option($  key))); ?>><?php echo esc_attr($  option_value); ?></option>                         <?php endforeach; ?>                     </select>                     <?php echo $  this->get_description_html($  data); // WPCS: XSS ok.?>                 </fieldset>             </td>         </tr>         <?php          return ob_get_clean();     } } 

I’ve been trying to use this generate_select_html function to generate this select input but I’m actually running with my eyes closed because I don’t know if this is right way to do things. That piece of code causes an infinite loading page on the billing form so it is wrong (obviusly). Is there a way to adchieve what I want?

Select all entries where range of two DATETIME fields includes given date

I’m looking for a way to get all entries from my reservations table to be shown in a calendar.

Now I know that I will have to iterate over all days of the current week and run a database query to select all reservations with dt_from >= start_of_the_week / start_of_the_day and dt_to <= end_of_the_week / end_of_the_day.

But that only gives me the reservations that start or end within the week / respectively within the given day.

What I am trying to figure out is: How do I get the reservations which started earlier and/or end after the current day or week?

I have some kind of the following table design

+----+-------------------+---------------------+---------------------+ | ID | NAME | DT_FROM | DT_TO | +----+-------------------+---------------------+---------------------+ | 1 | Jeff Atwood | 2020-01-06 09:00:00 | 2020-01-16 09:00:00 | | 2 | Terry Jones | 2020-01-30 09:00:00 | 2020-02-16 09:00:00 | | 3 | Brian of Nazareth | 2020-02-06 09:00:00 | 2020-03-16 09:00:00 | +----+-------------------+---------------------+---------------------+

I have been stuck with this for a while now and would appreciate a push into the right direction.

Thank you 🙂

How to select fields using alias name?

I have an select:

SELECT  tb_dim_equipe.no_equipe "EQUIPE",  tb_dim_profissional.no_profissional "PROFISSIONAL",  no_cidadao "CIDADÃO",  a.nu_cns "CNS",  sum(case when co_dim_tempo >= 20190100 and co_dim_tempo <= 20200131 then 1 else 0 end) as "TOTAL"  from ( SELECT no_cidadao,  tb_fat_cad_individual.nu_cns,  tb_fat_cad_individual.co_dim_profissional,  tb_fat_cad_individual.co_dim_equipe from tb_fat_cidadao_pec  join tb_fat_cad_individual on tb_fat_cad_individual.nu_cns = tb_fat_cidadao_pec.nu_cns  join tb_fat_cidadao on tb_fat_cad_individual.co_seq_fat_cad_individual = tb_fat_cidadao.co_fat_cad_individual  where st_mudou = 0  and st_vivo = 1  and st_gestante = 1  and tb_fat_cidadao.co_dim_tempo_validade = 30001231) a   left join ( SELECT tb_fat_atendimento_individual.nu_cns,  tb_fat_atendimento_individual.co_dim_tempo  from tb_fat_atendimento_individual  join tb_dim_tempo on tb_dim_tempo.co_seq_dim_tempo = tb_fat_atendimento_individual.co_dim_tempo  where co_seq_dim_tempo >= 20190100  and co_seq_dim_tempo <= 20200131  and ds_filtro_ciaps like '%ABP001%'  union SELECT tb_fat_proced_atend.nu_cns,  tb_fat_proced_atend.co_dim_tempo  from tb_fat_proced_atend  join tb_dim_tempo on tb_dim_tempo.co_seq_dim_tempo = tb_fat_proced_atend.co_dim_tempo  where co_seq_dim_tempo >= 20190100  and co_seq_dim_tempo <= 20200131  and ds_filtro_procedimento like '%0301010110%') b  on a.nu_cns = b.nu_cns  join tb_dim_equipe on tb_dim_equipe.co_seq_dim_equipe = a.co_dim_equipe  join tb_dim_profissional on tb_dim_profissional.co_seq_dim_profissional = a.co_dim_profissional  group by no_equipe, no_profissional, no_cidadao, a.nu_cns  order by no_equipe, no_profissional, no_cidadao 

This return to me five columns EQUIPE, PROFISSIONAL, CIDADÃO, CNS and TOTAL

I want to create a new select command like this:

SELECT sum(c.TOTAL) from *query above* c 

but I receive the error that column not exists.

How I can use a select with the names of alias columns EQUIPE, PROFISSIONAL, CIDADÃO, CNS and TOTAL?

Holding and dragging mouse to select multiple buttons/cells

Is it possible to create a TogglerBar-type object in which several buttons can be selected/deselected simply by holding the mouse’s left-click button and dragging it over the buttons? Similarly to the multiple selecting option when holding control and the mouse on Windows, but without the drawing box.

It seems that, by default, TogglerBar only selects a button when the left-click button is released, but I’m unaware of any way of doing what I want. Any ideas?

Just to give some context. I’m working with cell dynamics, and I intend to make it easier to select a large group of cells in an epithelium. This is, in some sense, a follow up to a question I made before regarding a “toggleable” Voronoi Mesh.