Questions tagged as 'sql-server'

1
answer

Select min () returning value other than 0

I need to make a select where you get the lowest value found, other than 0 (zero), SELECT MIN(VALORTARIFA) MENORTARIFA FROM TABELA In the above command, if there is any 0.00 value, it returns me 0.00 and I only want the highest value...
asked by 12.02.2016 / 13:51
1
answer

Parameter-based query in SQL Server

I have a situation where I need to bring results depending on the parameter reported. If I enter some number, that would be the code, it would only bring the result that has the code. If I did not report anything, it would fetch all the results...
asked by 17.12.2015 / 14:50
1
answer

Doubt with query in SQL Server

I have the following query in SQL Server, to return me a list of cities that I need. select IDCidade as "ID", case UF when 'RS' then '1' when 'SC' then '2' when 'PR' then '3' when 'SP' then '4' when 'RJ' the...
asked by 13.12.2016 / 14:32
3
answers

Return a sql command in a function

I wonder if it is possible to return a sql command on a function to run as a subselect. For example: Select *, produtos = (nome_da_function()) from Usuario Well, the way I did it, I was only able to return as a string inside a column....
asked by 20.10.2015 / 17:40
1
answer

SQL Server and JSON to generate Highmaps: very long and difficult to handle query

I set up the query below to have a JSON output assigned to Highmaps (from Highcharts), but it is very laborious and I would like to modify it if it is possible to make it smaller and easier to change it: select count(case when maior_uf...
asked by 18.01.2016 / 01:38
1
answer

How to concatenate variables

Dynamically, I'm capturing the name of the columns where it appears in two tables so after doing this insert an array of values of table_A in table_B. Using the CURSOR feature, I get the columns through a loop and then concatenate the...
asked by 05.02.2016 / 15:07
1
answer

Make a merge between multiple databases

I have a canteen system that performs sales in different schools. This system only works online, saving the sales movements in the array server (MS SQL). To optimize the system, I would like to work with it using a local base, so it would work e...
asked by 05.02.2016 / 12:50
1
answer

How to "truncate" table to restart from lowest auto increment value

The tabela_A has a id field with auto increment. I need to clear the table with something similar to the command truncate only cleaning only the registry from id = x . For example: id col1 1 A 3 B 4 C 5 D 30 E...
asked by 20.04.2016 / 23:25
1
answer

How to execute trigger sqlserver

How can I perform a trigger on unit tests. I have a trigger I have a trigger as an example: ***-- Create one trigger with two inserts:*** create trigger trg_I_Table_1 ON Table_1 FOR INSERT as insert into Table_2 (Col_1, Col_2, Col_3)...
asked by 18.04.2016 / 20:12
1
answer

add a foreing key to an existing table

I have to create a column in an existing table and at the same time create a foreing key with another table using this column that was created, and this foreing key by default must be null. The way I'm doing is IF NOT EXISTS (SELECT * FROM SY...
asked by 08.07.2015 / 21:09