Questions tagged [sql-server-2008]
Use this tag for questions specific to the 2008 version of Microsoft's SQL Server.
53,834
questions
-1
votes
0
answers
9
views
Database error while connecting mssql server
I am using macOS Monterey, trying to connect to mssql server using codeigniter. I installed php, sqlsrv 5.1(https://docs.microsoft.com/en-us/sql/connect/php/loading-the-php-sql-driver?view=sql-server-...
0
votes
0
answers
32
views
SQL Server : primary key violation on occasion despite prior deletion
I have a procedure that is supposed to replace an entry in my table by first deleting it based on an id and then inserting it with new values.
It looks like this, plus additional values used for the ...
-2
votes
0
answers
15
views
How to sync remote data from local database in Microsoft SQL Server [closed]
I am trying to sync two databases; when any change occurs in the local database with the online database to solve this kindly share the easiest method to solve this problem
0
votes
1
answer
25
views
How to convert IF or nested If statement like EXCEL to dynamic SQL Query in SQL server
I have came across one pretty problem in which I need to convert the nested if statement (like we used to write in excel) to dynamic SQL query.
I want to convert this
select 'IIF(A>B,A,IIF(B>C,B,...
0
votes
1
answer
31
views
Stop to bring duplicate results based in a condition
Even though my query is behaving the way it should be, I have an issue in the records that I can't fix in the database.
So, I want to fix it in the query.
The issue is: as the image attached, for one ...
0
votes
0
answers
34
views
Is it possible to capture the Connection Srting used to connect to SQL Server
I have recently taken over a number of SQL Server 2008 databases that are configured with mirroring. I understand there are some applications that connect using the "Failover Partner" option ...
0
votes
1
answer
35
views
TSQL distinct list, but with extra data if a single original item
Ideally I'd like SQL2008 compliant answers, due to customer constraints
I need a distinct list of items, but with a column that returns a specific piece of data if the original data only had a single ...
-2
votes
2
answers
52
views
Query column and get a list of all values that are not there
I'm looking to do a query against a table that has sample data like:
1000
2000
3000
4000
5000
The column is called sampleData and query it and get a list of all that are not there.
Example: where ...
1
vote
1
answer
34
views
Conditional on multiple insert
I have a lot of records I need to insert into an already massive table (the table has several million rows and I'm inserting several thousand rows at a time).
The current syntax being used is a simple ...
1
vote
2
answers
54
views
How to extract data from nested JSON in SQL Server
DECLARE @CONTACTS varchar(max)
SET @CONTACTS =
N'[
{"contacts":"[{\"idRole\":1,\"cdsid\":\"RWILS351\"},{\"idRole\":3,\"cdsid\":\"...
1
vote
1
answer
41
views
CTE performance issue when add one more field on selection list
I have a table with hierarchical data (contains ~5.000.000 records). I use the following query to retrieve all children records of a specific record:
with TEMP_PACKAGES as
(
select ID AS ...
0
votes
2
answers
54
views
Select rows with a duplicate ID but different value in another column
I have a table like this
I would like to select the Itemid that occurs more than once with a different Rate with group by Masterid
The output should be something like:
-1
votes
1
answer
65
views
What is the best practice to insert a row after some consecutive rows in a table?
I have the below data in a table:
REGION,CATEGORY,SUBCATEGORY,ItemName,ItemViews,sales,ItemViewspercentage
CE,Infotainment,Safe Exit Assist,Voice Commands,5,4,125.00%
EA,Infotainment,Safe Exit Assist,...
0
votes
1
answer
34
views
Find which where clause is the most troublesome
Problem background
I am trying to pin down to what condition(s) are causing no records / rows the most, so to allow me to find the root cause of what data in the database might need scrubbing.
So for ...
-4
votes
1
answer
92
views
Find distinct from multiple columns [closed]
I have 2 columns called price and PID in database called seatinginfo.
Both columns will have multiple of the same values like
pid 1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3
price 10,10,30,40,60,80,70,90,90,90,90 ...
0
votes
0
answers
33
views
In SQL Server I have Json format rows in column level need to create multiple columns # fields are not order we can create based on that
{zipCode=47715, state=IN, city=Evansville, countryCode=US, line1=7424 Eagle Crest Blvd}
{zipCode=10965, state=NY, city=Pearl River, countryCode=US, line1=One Blue Hill Plaza}
{zipCode=30339, state=GA, ...
0
votes
0
answers
31
views
Fast query runs slow in SSRS part 2
Referring to Fast query runs slow in SSRS my scenario is 1 row, 97 columns (I know a lot of columns - I can change the parameters to get more rows) also 9 parameters, I had a select statement calling ...
0
votes
1
answer
41
views
In Sql Server 2008, can I INSERT multiple rows with some fixed column values and some from a SELECT statement that uses one of the fixed values?
I’m building an insert statement dynamically to add multiple rows of data to a table in a batch, as I believe it is more efficient than inserting one at a time. However, I need the last couple of ...
0
votes
1
answer
37
views
Select column names based on condition in two separate table and database
I have the same table in two separate database (schema can be different so I use 'intersect') :
MyTable from Database1
MyTable from Database2
I want to get the column name, and if possible data, ...
1
vote
2
answers
37
views
Looping through a column to check if a cast succeeds in SQL Server
I am trying to check if an entire column which is varchar and make sure it can be cast to float. I have a cursor portion like so:
DECLARE @CastFailed BIT
SET @CastFailed = (SELECT SUM(...
0
votes
0
answers
18
views
Does the SQL Server IIF function accept defined column values?
I am trying to use the IIF function and would like the parameters value_if_true and value_if_false to be defined by a computed column value. More generally, can I use computed column values as ...
0
votes
1
answer
278
views
How to get Stream TypeORM result (SQL Server) by query method?
I need to get all data from the table in Stream format using Typeform.
Based on documentation it's possible to get stream data by calling the createQueryBuilder method.
await this.createQueryBuilder('...
0
votes
1
answer
44
views
Replacing last 32 character in an item in the table
sorry I tried to search about the topic and couldn't find what I need.
I have a table Called Products inside of it I have column called Serial and it's VARBINARY 64
I want to replace last 16 character/...
-1
votes
1
answer
50
views
Exec in a function SQL
I have a table where i am storing multiple values like below,
ColumnA
ColumnB
ColumnC
Book1
Author1
Station1
Book2
Author2
Station1
Book3
Author3
Station3
Now i wanted to have all books grouped ...
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
1
answer
34
views
Unioned select statements cause an int overflow error
I am trying to run this unioned select statement and I'm getting an int overflow error.
The first select has an ID which is an integer so I've cast it as a varchar(25).
This levels the playing field, ...
0
votes
0
answers
15
views
Publishing ASP.NET MVC App with DB connection
I am trying to publishing a ASP.NET MVC application that has db connection to a local sql server.
I want to publish this application along with db connection into a domain that should be available ...
-1
votes
4
answers
103
views
select and remove SQL records with a timestamp difference < 1 day
I need to select or remove records from badge-records that have a date difference less than 1 day
If 2 or more records exists within 24hours all of them has to be removed but one. (the first or last ...
0
votes
0
answers
47
views
Update data in 2 tables with inner join
I'm looking for a way to update the data in 2 tables with an inner join, but it doesn't work for me.
What I want is to update the data of the dbo.UserInfo table and at the same time the Coin field of ...
0
votes
3
answers
59
views
SQL Server - Sample Timeseries
In PostgreSQL we use:
SELECT * FROM generate_series(1, 100)
SELECT * FROM generate_series('2020-01-01 00:00'::timestamp,'2020-01-02 00:00'::timestamp,'1 minutes')
How do we create the time-series in ...
-2
votes
1
answer
26
views
Count invoices created in next 6 Months after current invoice for each customer - SQL Server
I have data set where I need to count invoices created within next 6 months a invoice is created including any other invoice created on same day. This is some sample data:
Customer
Invoice
Date
...
0
votes
1
answer
61
views
Insert does not enter the date correctly even though it is in the default format
I am trying to insert some data in SQL Server 2008 Express, in a newly created database, and a new table. When I execute the statement, it throws me an error saying the following:
Casting from ...
1
vote
2
answers
67
views
TSQL CTE error ''Types don't match between the anchor and the recursive part"
Would someone help me understand the details of the error below..? This is for SQL Server 2008.
I did fix it myself, and found many search hits which show the same fix, but none explain WHY this ...
0
votes
1
answer
195
views
Error while trying to insert Python dataframe into SQL table
I am trying to insert a .csv file's contents into a SQL Server database. I am able insert columns which has no nulls in my csv files. There are few columns which has few blanks due to which I am ...
1
vote
1
answer
33
views
Create an SQL query which returns date-dependent aggregate counts for distinct individuals and cumulative count of events in a table
--code to create a minimally reproduceable example
CREATE TABLE mre (
recid int,
caseID int,
t1 date,
t2 date,
t3 date,);
go
INSERT INTO mre (recid, caseID, t1, t2, t3)
VALUES (1, 1,'2018-04-01','...
0
votes
0
answers
42
views
How can I preserve the EncryptByPassPhrase returned value inside a subquery?
If you run this query:
SELECT rnd, rnd FROM (
SELECT RAND() AS rnd
) AS randvalues;
you will get same value in both rnd result columns, but if you run:
SELECT pass, pass FROM (
SELECT ...
0
votes
0
answers
37
views
Is there a way to Query views faster in SQL
I have a view that extracts from several tables but it is taking over 18 mins to retrieve the view. Is there any thing i can do to make it faster?
I thought of using a Index but do not know how to use ...
0
votes
0
answers
11
views
SQLSERVER Running Balance
Actually i have problem on my query to get the running balance , i have debit and credit transaction i need one column to showing the cumulative running balance this is the code i used :
Select * From ...
0
votes
0
answers
48
views
Delete column from two tables
I have two tables:
PROJECT with (id_project PK, Name, Timestamp)
MEASUREMENT OF PROJECT with (Measurement_ID, Project_ID FK, Measurement_id_project PK)
One project can be associated with several ...
-4
votes
1
answer
49
views
SQL Server How can we write a sql function which returns the records where getdate() is between FromDate and Todate
How can we write a sql function which returns the records where getdate() is between FromDate and Todate as follows
if getdate() exists between FromDate and Todate then return
elseif DateAdd(Year, -1,...
-1
votes
3
answers
75
views
COUNT DISTINCT if sum is zero
Need help to count the values in column A if sum of column B equals 0 group by column A.
SELECT
A, SUM(B) --???
FROM table
WHERE DATE = 'yyyy-mm-dd'
AND B = 0
GROUP BY A
0
votes
2
answers
205
views
How to update records in existing column using Spring JPA?
I am new to Java and spring. I have an existing database and table. I just wanted to update the records in the existing table. I have created a class and marked it with @entity annotation and I have ...
0
votes
4
answers
138
views
Merging multiple rows with same column in SQL Server
What is the most efficient method to combine multiple rows of values with the same column in SQL Server?
data table
category
segment
payment
01
A
1425
01
B
7647
01
A
6164
01
B
3241
And I'm ...
1
vote
5
answers
108
views
How to run only the first conditional OR in WHERE?
I have a query and I would like to get only those rows who satisfies the first OR condition. I want to check conditions such as if the first OR will not have satisfy condition, then I should see the ...
1
vote
1
answer
222
views
Very slow SQL query when using IP in connection string
I am having a real big headache with slow SQL query. I have two connection string which are as follows :
ConnectString1 = "Driver={SQL Server};Server=MSSQLSERVER5;Database=SchoolMain;Uid=Admin;...
0
votes
1
answer
25
views
Attempting to add a prefix to a column in SQL Server 2008
I'm trying to add prefix with a condition using 'from' x table then using where to specify the id
For example:
UPDATE tablenameX
SET columnnameX = 'prefix' + columnnameX
FROM tablenameY
WHERE ...
0
votes
2
answers
96
views
How to exclude ISNULL from WHERE condition with multiple conditions?
I have the following data:
DECLARE @tbl TABLE (
Id INT,
[Date_1] DATETIME2,
[Date_2] DATETIME2
)
INSERT INTO @tbl ([Id], [Date_1], [Date_2]) VALUES
(1, '2018-08-15 16:05:20.000', NULL),
(...
1
vote
1
answer
47
views
Using Like Condition in Join not giving desired output
I have 2 tables products, items and trying to join using product from products table and item from items table
Products:
Product
date
Dose
Acetaminophen
12/10/2020
0.5ml
Tylenol
06/10/2008
10ml
...
0
votes
1
answer
45
views
SQL Server : group entries by start and end event
Unfortunately I don't have a lot of experience with SQL Server.
I have a table with the following structure and sample data:
ID
Status
TimeStamp
68
2
10.01.2022 08:45:02
52
0
10.01.2022 08:44:29
...
1
vote
1
answer
43
views
Order Number Generation Based On Distributor Code
I need to generate Order number as below scenarios based on Distributor Code. Order number format will be as below
Order Number: Distributor Code/Retailer Code/TO/DDMMYYOrder
number(Order number will ...