Questions tagged [sql-server-2005]
Use this tag for questions specific to the 2005 version of Microsoft's SQL Server.
18,417
questions
-2
votes
1
answer
32
views
How will you find the latest inserted data in table without using primary key, date or id in SQL Server? [closed]
How will you find the latest inserted data in table without using primary key, date or id in SQL Server?
-1
votes
0
answers
22
views
Event ID 18204 error when I do SQL DB restoration
I am trying to restore the DB from Commvault backup from one DB 1 to another DB 2,But its is throwing some error in restore log and in DB 2 server I can see event id 18204 error.
What could be the ...
0
votes
0
answers
68
views
Linked servers, results query xp_cmdshell to table migration SQL Server 2005 to SQL Server 2019
I'm migrating procedures from Microsoft SQL Server 2005 to Microsoft SQL Server 2019 and I got stuck while trying insert query result xp_cmdshell in linked servers to table
I'm out of ideas
Old ...
-1
votes
1
answer
62
views
Subtract hours from current date time and compare to column value whose data type is datetime
I want all the MAFN column values that were added to the table in the last hour(:mm). The column ReturnDt stores the time it was added in DateTime format ex.'2005-01-11 08:50:24.767'
I can get the ...
1
vote
1
answer
41
views
Get the history values based on Revision Id
I have a two table table, first table storing all the latest data and second table to capture the changed data. For example if an user change value the FIRST table will update the data and SECOND ...
0
votes
2
answers
58
views
How to retrieve data from SQL Server 2005 on Windows Server 2008 R2 on static IP, in a secured manner to Power BI? [closed]
Situation
My company software is running on SQL Server 2005 on Windows Server 2008 R2 with a static IP.
Requirement
I wanted to access data for reporting into Power BI.
What I have tried so far
...
1
vote
0
answers
26
views
Prevent rspec from running migrations
I have a rails app with a sql server database. I manually create an empty database for rspec to test on with all the necessary tables before running the specs. Currently when running the specs the ...
4
votes
1
answer
77
views
Multi step table value function faster than inline table value function
I know, I know. It's not supposed to be this way.
Big picture, I'm working with map data and trying to determine which street a bus stop is closest to. A street is made up of a series of points. Some ...
0
votes
2
answers
65
views
Calculate Running Total Summary based on Different column
I need output like below
StockQty = 10
Balance Qty
[Allocate Stock Qty]
Shortage [Stock]
Running Stock
5.000
5.000
0.000
5.000
10.000
5.000
5.000
0.000
5.000
0.000
5.000
0.000
10.000
0.000
10.000
...
-1
votes
1
answer
60
views
Find Running Total In sql - if 1st column has no value then calculate from 2nd column
declare @tbl as table
(
ItemId int,
SOQty int,
DIQty int ,
IssueQty int,
BalanceQty int,
CreateDate datetime,
StockQty int,
WIPQty int
)
insert into @tbl values
(1,10,...
0
votes
1
answer
33
views
combining Rows in SQL which are in the same column
I am trying to combine two columns into two rows. I am unbale to work it out with the PIVOT table.
My table looks like this
name | status | timestamp
212 50 t1
213 50 t2
212 ...
1
vote
0
answers
35
views
Not able to fetch User who is having Permission as part of CERTIFICATE as Securable in SQL Server
Purpose of the query is to fetch all permissions for Particular user with all the details.
Please find my query below :
SELECT 'permUser1@master' AS dbUserName,
dp.NAME ...
1
vote
1
answer
26
views
Select Min() and other columns and GroupBy by two columns in EF 6
Using the example below, (from the answer in this link here) how can I select/group with an extra column ?
I have searched this site and others and tried some examples but couldn't get it to work.
// ...
0
votes
1
answer
40
views
Flask SQL Alchemy try perform SET operation, when it is not needed
I am facing a very strange issue using SQL Alchemy. I have a table in SQL server, to store Sales, with this format :
CREATE TABLE Resale (
[address] VARCHAR(100) NOT NULL,
[id] BIGINT NOT NULL,
[...
1
vote
3
answers
188
views
SQL Query to determine number of tables
I have this table and I'm trying to determine how many Tables (in a restaurant) are awaiting food.
The table( in the database) has the following columns:
TableNumber, ObjectType, ObjectDescription and ...
0
votes
0
answers
24
views
Remove Duplicate Rows in SQL 2005 with primary key identity seed and Date Time Stamps
Columns: ID (int) , Part (varchar), DF0 (varchar), DF1(varchar), DF2(varchar), DF3(varchar), DTI(DateTime)
All the samples I seem to find can get me the count or the data minus the ID and DTI.
I need ...
0
votes
1
answer
39
views
SQL: Running total with group by
I have a dataset that has two date columns for each transaction. An invoice date and a charge date. I am trying to do a cumulative or running total of the table in sql.
Data table looks like this
...
-1
votes
2
answers
66
views
SQL adding row if it does not already exist
Say i have this table
Product
Version
Value
1
1
1000
2
1
2000
3_a
1
2500
3
1
3000
2_a
1
1200
What i want to do is:
For each row where product does not end with '_a':
check if there is any row ...
0
votes
1
answer
57
views
LEFT JOIN returns duplicate SUM values
I have the following tables:
create table Invoices
(
InvoiceID int,
InvoiceNumber int,
InvoiceDate date,
SupplierName varchar(250),
SupplierCode varchar(20),
InvoiceValue decimal(18,2)
);...
0
votes
0
answers
133
views
IN condition with parameters using sqlalchemy
I'm need some help for making a query with SQLalchemy and SQL server using a simple web form.
Form fields are datefrom, dateto, and name so any user can filter the query base on their preferences.
...
0
votes
0
answers
31
views
How to add/update database tables, stored procedure, functions from existing .edmx file into a SQL Server database
I have cloned a project from Github which runs on ASP.NET MVC and Entity Framework.
I am facing a problem to generate database, tables, stored procedure and functions (All) from the .edmx file.
I do ...
-1
votes
1
answer
35
views
How do I get record with Max(date) and then compare values to get result
I am trying to get record with Max(StartDate) for each MeterNumber and then try to get records where startdate, enddate & RateCode is different for specific AccountNumber.
Sample data script as ...
0
votes
2
answers
49
views
How do I compare values from same column and different row but same table?
I am trying to get records where startdate is different for specific account Name. I have below sample data.
Sample data script as below
create table Meter (AccountNumer varchar(50), MeterNumber ...
0
votes
0
answers
28
views
Stored procedure starting with #
I was running a trace on an application today and saw this for the first time ever, in the text data of the trace:
exec #spDMF1F848FB98D743F69BA4AF02A7C05927
Can't seem to find anything online ...
0
votes
2
answers
68
views
How do I prevent duplicates from a SQL join?
I have the following tables:
customer:
id
customer_number
company
firstname
lastname
account_manager_email
email
comments
terms
tax_id_number
lead_source
default_catalog
credit_limit
99453
C00123456
...
0
votes
3
answers
678
views
Convert seconds to HH:MM:SS with hours more than 24
I want to convert 97200 seconds to HH:MM:SS format. I have used the below SQL Server syntax but it works as long as hours are less than 24 hours
select convert(varchar,dateadd(s,round(convert(double ...
0
votes
1
answer
33
views
Entity Framework Remote SQL Server
I have 2 machines, one that have an SQL Server with all the data in it, and another one that has the client dashboard.
Both machines are not physically in the same location, so the Entity Framework ...
0
votes
2
answers
438
views
Modify SQL_Variant Column to VARCHAR
I have a table where one of the columns has a sql_variant datatype. I'm trying to modify the column to VarChar(800) but I'm getting an error:
Implicit conversion from data type sql_variant to varchar ...
0
votes
0
answers
359
views
Connecting to MS SQL Server 2005 using PHP 8.0 or PHP 7.4
I am rebuilding a service that is using MSSQL Server 2005 along with PHP 4.3.11. There is a maintenance issue that I will need to address, and I would prefer to not write obsolete code now only to ...
0
votes
1
answer
491
views
When is DbContext.Entry(enttity).State = EntityState.Modified; required?
I want to clarify when I need to set the EntityState with Entity Framework Core.
Context: code-first C# Blazor Server App, SQL Server database.
Consider:
public async Task UpdateHelper(Helper ...
0
votes
2
answers
52
views
How to get the same result from aggregation
Like:
name
metric
A
1
a
1
SELECT SUM(metric), name
FROM table_name
GROUP BY name
Is there a way that I can get the same name every time I run this? How does SQL Server choose a or A to present?
0
votes
1
answer
67
views
Script to change the SQL Default database location in windows
Can someone help me with any script like windows script, BAT script or SQLcmd script for changing the default database location of SQL.
I am using Windows
0
votes
0
answers
49
views
Connect SQL Server and MySQL
I've a SQL Server 2005 on a Windows PC and I also have a MySQL database on another Linux server.
I'm looking for a way to combine both databases under a 3rd server, to run respective queries and ...
0
votes
3
answers
313
views
SQL - Remove pattern from varchar string
One of our applications was appending notes to the end of one of our columns, we have now removed this from the app and wish to remove existing from the data.
I have a pattern within Varchar (2000) ...
-1
votes
1
answer
48
views
Why is dbTimeStamp() adding a comma?
I have the following code:
$NOW = $db->dbTimeStamp(time());
And using that in a query it is producing a timestamp like this:
2021-01-13, 08:17:06PM
However, that comma seems to be causing the ...
2
votes
2
answers
3k
views
How to get timezone offset from the timezone name
I have a timezone name like America/Vancouver saved in a SQL Server database.
I want to get the UTC offset from the timezone name in SQL like America/Vancouver has -08:00 offset. So how can I write a ...
0
votes
1
answer
41
views
Connect two queries using join or any other method?
I'm using two tables. One is [Receipt Cash Book] (RCB) & other one is Banking Cheques. Some Records insert from RCB & Insert into BC. I wrote following queries to view records in RCB table
...
0
votes
1
answer
36
views
Running total for payments to the issued invoices
I have the following tables:
create table Invoices (InvoiceID int, InvoiceDate date, Total money);
insert into Invoices (InvoiceID, InvoiceDate, Total) values
(1,'2020-11-01', 20),
(2,'2020-11-01', 14)...
0
votes
1
answer
68
views
Running total SQL Server query
So far, I have the following SQL Server 2005 query:
WITH D AS (
SELECT CONVERT(VARCHAR, '2020.11.01', 102) AS d_y_m, CAST('2020-11-01' AS DATETIME) AS dt
UNION ALL
SELECT CONVERT(VARCHAR, DATEADD(dd, ...
-1
votes
1
answer
152
views
How to remove null values in lat long in sql
I am using this below query and it is giving me an error. The error that I am getting is at the very bottom. The error is caused by lat and long having null values in a few of my transactions. I ...
0
votes
1
answer
210
views
How to get table's metadata from linked server (SQL Server)
How to get tables metadata from linked server/another database? The query below works ideally when running on the main server, but returns null if calls remote server or even another database.
select ...
1
vote
1
answer
32
views
INSERT with selected value
From the Table:
user | groupId
-------------------------
A | 1
B | 1
B | 2
C | 1
C | 3
I would like to find all the records without groupId = 2 and thus insert it, ...
0
votes
0
answers
48
views
Which SQL server version supports varchar(MAX) data type
We should use varchar(max) when length of string varies and max limit is 2GB.
Is it supported in older versions like SQL server 2005?
If supports then still the MAX size limit is 2GB?
1
vote
0
answers
35
views
XML Parsing in SQL
I have to parse the below xml query
DECLARE @xml XML,
@Columns VARCHAR(MAX)
set @xml='<d><record1><columnA>1</columnA><columnB>as</columnB><columnC&...
0
votes
2
answers
47
views
Occurrence in MS SQL Server
create table #Task (ID int, Name varchar(1), Occurrence int)
insert into #Task values (1, 'A', 2)
insert into #Task values (2, 'B', 3)
insert into #Task values (3, 'C', 1)
insert into #Task values (4,...
0
votes
2
answers
747
views
Alternative for lead() function in SQL Server 5
I want the same output as lead function do for window function. I want to do it for SQL Server version 5.0
Table Name: Table
EventID CID Date
123 1 01-12-2020
123 2 01-12-2020
123 ...
0
votes
1
answer
98
views
Count data from two columns in one or two queries
I have the following distinct rows in my table:
JobID ClientID Date URL
a 1 Apr 27 2020 8:21AM http://somewebsite.com
a 1 Apr 29 2020 12:57AM http:/...
1
vote
2
answers
132
views
How can I insert a value into a table where the column contains special character?
I would like to insert a record into an MsSql data table. It is an easy thing, but the target table contains special naming columns like:
<"mz,x",int>
Unfortunately I cannot rename the ...
0
votes
1
answer
62
views
How to run CRUD in single procedure by using json?(T-SQL)
Procedure
ALTER PROCEDURE [dbo].[SpProductTsk]
(@json varchar(MAX))
AS
----insert---
BEGIN
DECLARE @SelectedProcedure varchar(max) = ''
IF @SelectedProcedure = 'SpProductIns'
...
0
votes
2
answers
34
views
i need to use when in sql view
Please its just a simple question , and i did it before but i cant do it right now .
i need to write when in column in sql view to give me value based on another column
as shown in the pic below
i ...