Questions tagged [sql]

187714 questions
1

votes
2

answer
3.3k

Views

SQLite Union of n tables with m columns

I have this problem. There are n tables created dynamically and each table has m columns, the columns could be repeated. This tables have in common 2 columns but there is no related data between them, for example: Table1 | A | B | Col1 | Col2 | Table2 | A | B | Col3 | Col4 | Table3 | A | B | Col1 |...
cbedoya
1

votes
1

answer
119

Views

T-SQL Select, ensure manager row comes before employee

Here is my problem. I have a table of employee data, which contains the username of the employee and their manager's username like so ______________________________________________ | employee_username | employee_manager_username| ------------------------------------------------ tom01 |...
Black Dynamite
1

votes
2

answer
1.9k

Views

How do I Copy Results With Headers from a 'View' in SQL Server 2008 R2 Management Studio

I'm having difficulties determining how to copy/export the headers for a 'View' I created. With my tables if I right click on the query results, I see an option to Copy with Headers as in this picture: But when I try the same for results from a custom view, I don't see the option to Copy with Header...
Rob G
1

votes
2

answer
1.3k

Views

Update or Insert value if a field is NULL

I know this is a very simple question but I just wanted to be sure. I have a Null value in a field, and I want to change that Null value. To change the Null Value Do I use Insert or update? For Example: Insert Into dataTable (Column 1) Values (1) WHERE 'Column 1' = NULL OR UPDATE dataTable SET 'C...
Hotlansy Httlandy
1

votes
3

answer
14.2k

Views

Netsuite custom formula field using a CASE statement with multiple WHEN conditions returning “invalid expression”

I'm quite new to writing NetSuite sql case statements. I have been able to successfully write CASE statements with single WHEN conditions but when I include multiple WHEN conditions NetSuite returns "invalid expression" error. I am wondering if I need to separate the WHEN conditions with something o...
Rick
1

votes
3

answer
654

Views

I have hash my password, but when I login, it does not recognize

Previously i have hash my password with this $password = hash('sha256' , $salt.$password_arr[$i]); and in config.php , i have this code to salt the password $salt = '[email protected]'; So my sql database display the hash code when i register a new pass into it, im happy with t...
nickee89
1

votes
1

answer
72

Views

my php is returning null when values are passed to it

my php is returning null when values are passed to it i checked it with chrome's plugin POSTMAN... i am unable to figure out the problem :\ This is my code i am trying to update the database by sending values from my android code(which is okay):-
Harekam Singh
1

votes
2

answer
171

Views

Select entries which doesn't have specified key

Assume, that I have bunch of entries in a document: db.document and some of them doesn't have some key, let's say name. So we have two types of entries - with and without name. { "_id" : ObjectId("4dea81a8bd2bb0323800002d"), "fetched_at" : ISODate("2013-08-02T17:41:30Z"), "keyword" : "110770", "n...
ciembor
1

votes
1

answer
29

Views

Select object that has no pointer

I have 2 entities named ContentState and HashedFile. Each record of ContentState has a HashedFile linked to it but the relationship is not unique and so there is a many to one relation regarding ContentState with unique="false" and not-null="true" (thus, 2 or more ContentState records can point to t...
little ali
1

votes
2

answer
881

Views

How to optimize/cache Rails query

I've Rails application where query takes way too long time. It uses postgresql DB and query consists of one table with thousands of records. statistics_controller.rb all_data = Usagedata.select([:start_time, :end_time, :node_count, :processors, :id, :wall_duration, :local_user_id]) .where(Usagedata...
Raccoon
1

votes
2

answer
1.2k

Views

sql server stored procedure spatial data

I am new to Spatial data types and SQL server as well, I have the following tables: Table (A) ZipCodesUSA Columns: zipcodes| latitude| longitude| city| state Table (B) US_Cities_longitude_Latitude Columns: ID int| City nvarchar(40)| Coordinates GEOGRAPHY| What I am trying to do is to create an SPR...
simon
1

votes
2

answer
1.9k

Views

Date parameter in SQL Server stored procedure from ASP.NET

I've written an SQL Server stored procedure that, amongst other things, accepts a date parameter: CREATE PROCEDURE data.addScore ... (some parameters), @testDate date AS On an ASP.NET page I have a textbox with a Calender Extender control (from the AJAX Toolkit) that allows the user to select a date...
Katstevens
1

votes
1

answer
6.3k

Views

Postgres windows function with aggregate group by

I want to get a list of email domains and the top user within each domain. My approach is to sum the questions per email grouped by the domain and then get the top user with a window function. However this does not work: SELECT domain, sum(questions_per_email) as questions_per_domain, first_value(e...
Kristoffer
1

votes
2

answer
9k

Views

SSIS Assigning value to Variable using Script Task

I am trying to assign a value to a variable from a flat file in an SSIS package. The script i am using is below #Region "Imports" Imports System Imports System.Data Imports System.Math Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper Imports Microsoft.SqlServer.Dts.Runtime.Wrapper #End Region ' This...
jeastham1993
1

votes
2

answer
538

Views

Transpose SQL result set

I have data in the following format: Machine | week_end | widgets A | 05-26-2013 | 5 B | 05-26-2013 | 4 A | 04-01-2013 | 6 B | 04-01-2013 | 0 I want my result set to look as follows: Machine | 05-26-2013 | 04-01+2013 | ... A | 5 | 6 | B | 4...
BenDundee
1

votes
2

answer
61

Views

How to avoid doing two separate passes while querying through a table?

The context of this problem are hospital visits. The logic is a bit convoluted but these are the requirements. Table Visits contains the names and visitIDs for the patients. Table FilteredVisits contains certain visits that meet some criteria The report is run under a certain date range - this is im...
Gabe
1

votes
2

answer
88

Views

Which Linq join will work for my scenario, confused

I have a web api project. In database I have two tables of comments and pictures. I want to use join to merge these two tables in such a way that every picture should have all the comments related to it. Both tables have picture id. Which join should I use? I need to use linq. Can someone tell me...
Obvious
1

votes
2

answer
460

Views

combination of unique values a column in a table

I need to find the all unique possible combination of values in a column in a table. For example, for column values 1,2,3,4,5. i want the result to be [1,2],[1,3],[1,4],[1,5],[2,1],[2,3] etc. Will appreciate any pointers to construct the query to find the combination of the values. thanks
sunil
1

votes
1

answer
126

Views

Normalizing and composite table structure

I have difficulty to optimizing the database design in a situation There is a table with 3000 employees and another one table with 300 departments. Problem is there is a possibility to 3000 employees in 300 departments. Basically each employee will work in all department 300x3000 records (worse ca...
aas
1

votes
2

answer
1.5k

Views

MYSQL select unique id's where column value is not null in one or more records

Background I have a table that contains customer purchase records, the table has a column named coupon_id, this column is null if a customer didn't use a coupon during a purchase and contained the coupon id if they did. The table can contain several purchases for a single customer, a customer may ha...
Levi Putna
1

votes
2

answer
3.4k

Views

Cannot see Databases In Visual Studio SQL Server Object Explorer after previous database dropped

I used to be able to see all databases in the SQL Server Object Explorer in Visual studio 2012. I dropped one of the main databases that I used to work with in VS, now I can no longer see any of the other databases. I can connect to the Server (SQL Server 2012) but the database tree is empty. Screen...
Asynchronous
1

votes
1

answer
248

Views

coding (unicode) hex to octal

I read a text file, which has some characters like that '\260' (it means '°'), and then I add it to DB (sqlite3). After that, I try to get the information from DB, but the sql-query will be built with '\xb0'(it means '°' too), because I get this information from XML file. I try to replace hex ch...
user2973395
1

votes
1

answer
9.8k

Views

Looping through database ResultSet

I have a snippet of Java code here which is supposed to retrieve results from a database query and the ResultSet is supposed to iterate through the values in order to retrieve certain API data for each entry of the ResultSet. However, the problem is that I can retrieve API data for only the first en...
Kanishka Ganguly
0

votes
4

answer
39

Views

Selecting multiple values into single row - SQL server

I need to merge a table with ID and various bit flags like this ----------------- a1 | x | | x | ----------------- a1 | | x | | ----------------- a1 | | | | ----------------- b2 | x | | | ----------------- b2 | | | | ----------------- c3 | x | x | x | into such form --------...
Astroc
0

votes
1

answer
36

Views

Getting exact day values per month, between 2 dates

I am trying to get the amount of days in a month, between 2 dates. So this would ideally look like Month | Days Jan | 5 Feb | 28 March | 5 The dates need to come from a table that looks like this - Name | Age | Address | AddressStartDate| AddressEndDate Steve| 19 | randomAdd | 2018-01-26...
sam smith
-2

votes
0

answer
34

Views

MS SQL calculate storage per Day and Month

Need help, a lot of help actually. Our company charges storage to customers per pallet. so we will charge base on days or Months, depending on the client. for example i have a table Pallet. ID, PalletNumber, qty a table palletlog. PalletNumber, qty, action, date. when a new pallet is made or r...
Juan G
0

votes
2

answer
34

Views

SQL join giving duplicate rows with group by clause

Thanks for all help i am facing issue while using joins Using one sccm query select count(distinct resourceid) as ModelCount,caption0,CSDVersion0 from [dbo].[v_GS_OPERATING_SYSTEM] where caption0 like '%Windows Server%' group by caption0,CSDVersion0 Data iam getting is as following so iam getti...
deepti
-3

votes
0

answer
38

Views

SQL Error when updating a table in my PHP form [on hold]

So I'm trying to get this request to work, however despite the "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''" I can't seem to find an error in the syntax. Here's the code : $request["update"] = "UPDATE ap_stu...
Outjacked
0

votes
1

answer
23

Views

Trailing spaces cant be removed in WHERE clause?

I need to list out the records with same records in column_A & column_B both are of varchar(50) type. But the issue is Column_A has trailing spaces in it, Even though both the columns having same data but it couldn't match. I tried to LTRIM(RTRIM(column_A)), REPLACE(column_A, CHAR(32), '') etc., bu...
Adithya Alapati
0

votes
0

answer
9

Views

How do I set a boolean value on a column that can be used in my MVC Web Application?

In my MVC web application I have a model class that talks to a SQL database view that is stored in my Azure SQL Database. The model looks like this: namespace GanttTest.Models { [Table("GanttTest")] public class Task { public int Id { get; set; } public string Text { get; set; } public DateTime? St...
Yanayaya
0

votes
0

answer
13

Views

sql query to set the cell value as the difference between another cell in another column minus the prior result

Dear all i have tried the following query but it troughs error, UPDATE dbo.SFData SET KPIperMonth = (SELECT KPIValue, KPIValue - LAG(KPIValue) OVER (ORDER BY SFID) PreviousValue from dbo.SFData) what i have is a table as follows SFID|KPIValue|KPIperMonth --------------------- 1 |1 | 2 |3...
Aris Biris
-3

votes
0

answer
34

Views

SQL Error when updating a table in my PHP form

So I'm trying to get this request to work, however despite the "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''" I can't seem to find an error in the syntax. Here's the code : $request["update"] = "UPDATE ap_stu...
Outjacked
11

votes
3

answer
14.6k

Views

Using column name when using SqlDataReader.IsDBNull

Hello I have got this code which reads data from SQL DB. I don't know how should I edit it so I can use original column name and not column index. string query = "SELECT * FROM zajezd WHERE event='" + thisrow+ "' AND year='" + klientClass.Year() + "'"; SqlCommand cmd= new SqlCommand(query, spojeni);...
Marek
1

votes
0

answer
17

Views

Usage of Power BI Interactive visualisations with Parent-Child dataset relations

I have been meddling with Power BI for almost a week now. It seems like a powerful tool, when you get to know your way around it at least.. I would like to be able to see the sum of Therapists, Admins and Citizens, based on all subgroups for the currently selected group. Here is my example: When i s...
Kalrin
1

votes
2

answer
179

Views

MS SQL distinct function

I have the query below SELECT distinct count(patient.id) CAST(YEAR(completiondate) AS VARCHAR(4)) + '-' + CAST(MONTH(completiondate) AS VARCHAR(2)) AS Mjesec FROM .... WHERE incident.completionDate Between Convert(smalldatetime, '01/10/2007', 103) and Convert(smalldatetime, '01/11/2013', 103) a...
tequilaras
1

votes
3

answer
585

Views

Store results of SQL Server query for pagination

In my database I have a table with a rather large data set that users can perform searches on. So for the following table structure for the Person table that contains about 250,000 records: firstName|lastName|age ---------|--------|--- John | Doe |25 ---------|--------|--- John | Sams |...
kshep92
1

votes
4

answer
110

Views

MYSQL: Find all posts between certain users

I have two tables: table message (holds the creator of a message and the message) id - creatorId - msg and a table message_viewers (tells who can read the message msgId) msgId - userId If I create a message as user 1 and send it to user 2 and user 3, the tables will look like this: tbl_message:...
user3010549
1

votes
2

answer
1.6k

Views

Cloud SQL using mysqli error

I'm trying to output the results of a simple query using a Google Cloud SQL with a mysqli connection. I've properly set up a Cloud SQL instance and imported a SQL database. However, when I run my app, it seems to connect to the database - no errors are triggered there - but the logs show the followi...
Joe Lowery
1

votes
3

answer
1.7k

Views

Accumulate rows in SQL: summarizing previous values and new grouped by date

In SQL Server 2008, If I have a table like this. Date NoOfCases -------------------- 2013-11-27 1 2013-11-28 2 2013-11-29 1 2013-11-30 3 And I want the previous sum to be added to the next row's value. That means that the output should be like this: Date AccumulatedNoOf...
guitarzero
1

votes
3

answer
92

Views

Optimization of an MSSQL Database

Briefly I would like to explain my project. I have already built an eCommerce website (ASP.NET C# MSSQL) where users are asked to register before payment (in case if they are not registered). Whenever a user register, 1 table is created automatically using C#. The purpose of this table is to store d...
Facbed

View additional questions