Questions tagged as 'sql-server'

2
answers

How can I replace the NULL with a text string in a query in sql?

SELECT MONTH(pag_fecha) AS Mes, SUM(pag_importe) AS Ingresos FROM PAGO GROUP BY MONTH(pag_fecha) WITH ROLLUP I would like instead of NULL to get me "Total income" I already tried it with a CASE but I want to know if there was a simple...
asked by 30.04.2018 / 04:51
1
answer

How can I do a PIVOT with Dynamic columns?

I have a problem when generating a query using the PIVOT function of SQL - server 2008. The query itself has no disadvantages, since the values it throws are correct. For EMP3 the query throws totally NULL or 0, this is correct, but I need to ge...
asked by 04.11.2017 / 15:06
2
answers

Display data without repeating

I need help with my sql query. My query is: select * from matricula and show me this information: nummatri fechamatri dnialum idnivel idgrado idsecc año 3 2017-12-20 12357890 2 7 14 2018...
asked by 22.12.2017 / 03:36
1
answer

Join results in SQL Server

I would like to know how I can do to join the results of several selects in the same temporary table if possible, or if there is another way to do it. This is the code that I have at the moment: Declare @mod as int; Declare modelos c...
asked by 26.12.2017 / 21:40
1
answer

How to subtract the results of a query in SQL?

I have the following query: SELECT ID,PLACA,SUM(GALONES) AS GALONES,SUM(MONTO) as MONTO,MONTH(FECHA1) MES,YEAR(FECHA2) AÑO FROM [db_stransportacion].[dbo].[v_combustible_Asignado] c INNER JOIN [db_stransportacion].[dbo].[t_Vehiculo] v ON c.ID=...
asked by 09.03.2018 / 16:34
1
answer

Verify the name of a varchar field and concatenate an int in case it already exists

I am reprogramming a calendar to save tasks to perform and I need a stored procedure that allows me to verify if the name of the task exists in the 'subject' column of my Appointments table, if it exists it must modify the name adding it at the...
asked by 11.08.2017 / 15:03
2
answers

Fill combobox with database, but start with white

I have a combobox that I filled with this database query: select ' ' as usr_entrada, null as no_servicio union select usr_entrada, No_Servicio from Telemarketing where Id_Sucursal='cordoba' The idea of the union is to add a blank row to th...
asked by 31.07.2017 / 16:58
1
answer

Change database using variable @databaseNameVariable

How to change the database with the name of the base stored in variable ?; Do the following code, however, do not change the database. DECLARE @inicio VARCHAR (100) DECLARE @bdname VARCHAR (100) DECLARE @usedb VARCHAR (100) SET @inicio =...
asked by 21.08.2017 / 20:18
1
answer

Export I leave without the name of the columns

I'm trying to export a table and I get it right but without the headers. Can you help me? This is what I have done so far declare @sql varchar(8000) select @sql = 'bcp "select * from Ana.dbo.detalle_incidencias" queryout C:\prueba.csv -c -t, -...
asked by 22.05.2017 / 10:39
2
answers

Error: An INSERT EXEC statement can not be nested. SQL Server 2008 R2

I have an sp which I want to store inside a temporary table, either a table variable or a temporary table, in both cases, this error marks me:    An INSERT EXEC statement can not be nested. This is my code that I am generating to store th...
asked by 05.06.2017 / 17:38