Quantcast
Channel: Getting started with SQL Server forum
Viewing all 9243 articles
Browse latest View live

SQL Server 2016 - Space Available

$
0
0

I can't find exact answer on my question. When i right click on any database in SSMS, i see "Space available parameter". Is this free space in mdf file only or it include transaction log file too (free space in mdf + ldf files together)? Thanks

I asked because ... I have a table (size about 450GB with 5 millions rows) with LOB data. Application support delivered this script to delete some rows (should delete about 300K rows).

declare@cnt int;declare@cnt_total int =0;set nocount offwhile1=1begindeletetop(5000)-- PARAM BATCH_SIZEfrom fw.fw_o_clobwhere DT_TEC_CREATED <'2019-01-01T00:00:00.0000000'AND ID_CLOB <>-1;set@cnt =@@ROWCOUNT;set@cnt_total +=@cnt;if@cnt =0break;end;print concat('Total ',@cnt_total,' rows deleted.');
go

But when we run this, "Size DB" started growing (info from properties) - this is OK, because transaction log started growing but what is interesting "Space available" was getting smaller and smaller so we canceled it. Can someone explain me why? Thanks


Error converting data type varchar to float.

$
0
0

I have latitude and longitude data which are as below.Below values are VARCHAR in a table. when I try to convert it into Float it gives me error : "Error converting data type varchar to float."

I tried to use CAST(Latitude AS FLOAT) and CONVERT(Float,Latitude). Can you please let me know how I can convert these values to Float?

43.6432
33.53645
49.4629
49.5041
49.5041
49.4617
20.75575
49.4617
28.8809
28.8843
28.8874
28.8781
28.879
28.8843
28.8809
28.8781
28.8843
28.8843
49.690120
40.05052
44.13446
33.6611

bulk insert with file format with manual values for null fields

$
0
0

I would like to create a stored procedure that imports a txt file into an existing table using a format file and also update certain fields that will be null in the import. The import file will just update one column and I need to manually assign values for the other columns.

bulkinsert QueryData from'E:\TrackInputLogs\NMSLog.txt' 
with(FORMATFILE ='E:\TrackInputLogs\NMSFormat.fmt', 
ROWTERMINATOR
='\n') 

I need to update the following columns as follows at the same time

dateimported = getdate() 
idkey
= asdfg 
importmethod
= manual 

oh by the way, this is an existing table and I do not want to delete current contents but also the import will update the fields where the idkey matches the values associated with the file contents.

How to use Add-RoleMember

$
0
0

I would like to create a login user  and assign him db_datareader in a particular database.Using the below code

Import-Module SqlServer

$SQLInstance = "xxx\SQL2017"
Add-SqlLogin -ServerInstance $SQLInstance -LoginName 'apac\abc' -LoginType WindowsUser -Enable -GrantConnectSql
Add-RoleMember -Database 'test' -MemberName 'apac\abc' -RoleName 'db_datareader' 

and I am getting the below error

Add-RoleMember : A connection cannot be made to redirector. Ensure that 'SQL Browser' service is running.
At line:4 char:1
+ Add-RoleMember -Database 'test' -MemberName 'apac\abc' -RoleName  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (apac\abc:String) [Add-RoleMember], ConnectionException
    + FullyQualifiedErrorId : Microsoft.AnalysisServices.PowerShell.Cmdlets.AddRoleMember

I tried using examples described in 

https://docs.microsoft.com/en-us/powershell/module/sqlserver/add-rolemember?view=sqlserver-ps

Is there any requirement for enabling any services like Microsoft.AnalysisServices for using Add-RoleMember 


Contoso backup file not being detected by SSMS

$
0
0

I am trying to get the Contoso data set to help learn Power BI. I have downloaded sql server express and SMSS 17.1, and tried to connect. Nothing at all, the .bak file was not being found.  I checked and found this

 https://msdn.microsoft.com/en-us/library/ff720227.aspx

and ran the query.  I now have a contoso database, so in the source I have in the Device option the path to the ContosRetailDW backup file. In Destination I have been able to select Contoso from the database pull down options. However, restore to/timeline is greyed out, and I can go no further as the OK button is greyed too.

Can anybody advise me in non-technical terms what else I need to do to get this set up please?

thanks

Login is from an untrusted domain

$
0
0

Hi

I have searched all over the internet for answer so hopefully someone here can help.

I have an SQL 2017 server set to use Windows or SQL authentication.

The DB's that are on it work fine using either authentication method on the LAN.

My issue is that when a user tries to connect over our VPN it will fail with the above error message about its login is from an untrusted domain. 

However, if I use an SQL credential (SA) it connects no issues.

I have read all sorts about SPN's and running the MS Kerberos tool to fix SPN's but this tool wont run either remotely or on the server itself reporting "issues accessing UserAccount information"

I am a complete novice is this area so if anyone can help please dont get too technical :-) 

Query Result Not Returned As Expected

$
0
0

I am struggling with a query that tried few days back with a suggestion of one of my friend and got it work with the following using LEAD/LAG function:

WITH your_table(ID, STOREDATE, VALUE, INFO)
AS
(
SELECT 1122,'1/1/2020',2,'DONE' UNION ALL
SELECT 1122,'1/2/2020',7,'DONE' UNION ALL 
SELECT 1122,'1/3/2020',1,'DONE' UNION ALL 
SELECT 1122,'1/4/2020',7,'DONE' UNION ALL 
SELECT 4466,'1/1/2020',2,'DONE' UNION ALL
SELECT 4466,'1/2/2020',7,'DONE' UNION ALL
SELECT 4466,'1/3/2020',1,'DONE' UNION ALL
SELECT 4466,'1/4/2020',8,'DONE'
),

CTE AS
(
    SELECT ID,
    STOREDATE,
    VALUE,
    CASE 
        WHEN VALUE = 8 THEN 0
        WHEN VALUE + LAG(VALUE) OVER(ORDER BY ID, STOREDATE) = 8 
            AND ID = LAG(ID) OVER(ORDER BY ID, STOREDATE) THEN 0
        WHEN VALUE + LEAD(VALUE) OVER(ORDER BY ID, STOREDATE) = 8 
            AND ID = LEAD(ID) OVER(ORDER BY ID, STOREDATE) THEN 0
        ELSE VALUE
    END VALUE2,
    INFO
    FROM your_table
)

SELECT *,
CASE 
    WHEN 
        (
            SELECT COUNT(*) FROM CTE A 
            WHERE A.VALUE2 = 0 AND A.STOREDATE < B.STOREDATE
            AND A.ID = B.ID
        ) >= 1 AND B.VALUE = 8 THEN B.VALUE
    WHEN
        (
            SELECT SUM(A.VALUE) 
            FROM CTE A 
            WHERE A.VALUE2 = 0 
            AND A.STOREDATE < B.STOREDATE
            AND A.ID = B.ID
        )>= 8  THEN B.VALUE
    ELSE B.VALUE2
END VALUE3
FROM CTE B;

My idea is to get sum of 8 or value 8 at any given row for specific id. So for the above input, my expected output is this:

ID      STOREDATE   VALUE   INFO
1122    1/1/2020    2       DONE
1122    1/2/2020    0            //1 + 7 = 8; it'll update both the rows with zero
1122    1/3/2020    0            //For this, it's just fine
1122    1/4/2020    8       DONE //Will not update as I've the sum of 8 or 8 above once

Now my problem is with the below inputs that I can't figure out how to get expected result set.Here are the samples:

Input:

ID      STOREDATE   VALUE   INFO
1122    1/1/2020    2       DONE
1122    1/2/2020    1       DONE
1122    1/3/2020    2       DONE
1122    1/4/2020    7       DONE

Expected Output:

ID      STOREDATE   VALUE   INFO
1122    1/1/2020    2       DONE
1122    1/2/2020    0       
1122    1/3/2020    2       DONE
1122    1/4/2020    0  

Input:

ID      STOREDATE   VALUE   INFO
1122    1/1/2020    2       DONE
1122    1/2/2020    2       DONE
1122    1/3/2020    2       DONE
1122    1/4/2020    2       DONE

Expected Output:

ID      STOREDATE   VALUE   INFO
1122    1/1/2020    0       
1122    1/2/2020    0       
1122    1/3/2020    0       
1122    1/4/2020    0 

I am not sure how to get the result set and is there a way I can make tweaks to the above query to make work? Any idea would be highly appreciated - Thanks.


Get data from CDATA xml in Sql server?

$
0
0

Hi,

I have CDATA xml in a column..

DECLARE @doc XML = 
'<Parameters><Options><![CDATA[[{key:"1" , value:"value-1"},{key:"2" , value:"value-2"},{key:"3" , value:"value-3"},{key:"4" , value:"value-4"}]]]></Options><DefaultText><![CDATA[1]]></DefaultText></Parameters>';

How to acheive output like below ?

key	value
1	value-1
2	value-2
3	value-3
4	value-4

I couldn't get data when I tried something below.

DECLARE @doc XML = 
'<Parameters><Options><![CDATA[[{key:"1" , value:"value-1"},{key:"2" , value:"value-2"},{key:"3" , value:"value-3"},{key:"4" , value:"value-4"}]]]></Options><DefaultText><![CDATA[1]]></DefaultText></Parameters>';

DECLARE @hnd INT;
DECLARE @json NVARCHAR(MAX)

EXEC sp_xml_preparedocument @hnd OUTPUT, @doc;  

SELECT text FROM OPENXML (@hnd, '/Parameters',0) where parentid=2;

--SELECT @json=text FROM OPENXML (@hnd, '/Parameters',0) where parentid=2;

SELECT * FROM OPENJSON(@json);

EXEC sp_xml_removedocument @hnd;  

Thanks in advance..


Connectivity issue to custom SQL port remotely

$
0
0

Hi guys. I have two Windows 2016 R2 servers, one being installed with SQL 2019. I have custom the port to listen at a different port than the standard 1433. The SQL port is listen locally, able to telnet via hostname, localhost on the dedicated port.

Now the issue is with the application server connecting to this SQL server. The firewall is opened, we can see the traffic is allowed. However the thing is, the telnet test may seems incomplete.

The application server (being the client), sends SYN_SENT and stopped. While the SQL server SYN_RECEIVED at the right port. There's no connection established. The SQL configuration is correct as we allowed remote connection, and all interfaces are setup with the correct port. Is there any config to be fixed or if this is SQL server behavior? 


Evan Ting

Enlist TSX Progress Issue

Case Statement using LIKE and LIKE

$
0
0

Hi 

Can you use the LIKE twice within a CASE statement and if so, how is it written please?

case when factory LIKE '%QT' AND factory LIKE '%TT' THEN 1 ELSE 0 END AS FACTORY_NEW

SSAS Error received - A connection cannot be made. Ensure that the server is running. (Microsoft.AnalysisServices.AppLocal.AdomdClient)

$
0
0

Dear All

I recently installed Microsoft SQL Server Management Studio – V19.9.1. Any one can volunteer – will love to do skype call and show my desktop to get this issue resolved. Otherwise, please help sharing some guidelines. Whenever I am connecting to the Analysis Server through SSMS, I am getting the following error

A connection cannot be made. Ensure that the server is running.(Microsoft.AnalysisServices.AppLocal.AdomdClient)

  1. Successfully login to SQL Server Management Database (both with Windows and SQL Auth
  2. Error received - A connection cannot be made. Ensure that the server is running. (Microsoft.AnalysisServices.AppLocal.AdomdClient)

Make the database drop down wider?

$
0
0
I've tried grabbing this and dragging it left/right to see if it would increase in size, but I could only move it side to side.  Is there a way to make the drop down in SSMS that displays the databases attached to the current instance wider?

SQL Server Error: 1326

$
0
0

I have an Access front-end connected with a cloud-based SQL Server 2019 db.  The front-end connects with no issue up in the cloud using an IP address and TCP so I think my connection string is good.  However, if I try connecting from my PC here on earth I receive the following message:

Connection failed:
SQLState: '01000'
SQL Server Error: 1326
[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()).
Connection failed:
SQLState: '08001'
SQL Server Error: 17
[Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.

Thanks!


direct link to download the offline installer for SQL Server 2019 express?

$
0
0

Hi, where can I find the direct link to download the offline installer for SQL Server 2019 express edition?

The official download page only provides a way to download the network-install exe.

Although I know I can choose to download the offline install media using that exe, it's not easy to use such exe in WIX. I want my Wix project to automatically download SQL server 2019 express and install with command line parameters (e.g. Features=SQLENGINE,REPLICATION), but these paramters cannot be passed to the exe above (it only accept ConfigurationFile="myFile.ini", which means I have to store my config in to a physical file and use it during installation).

It works fine for SQL Server 2017 express as my wix project can download the full offline installer for 2017 from Microsoft download center, but I just can't find 2019 express offline installer on Microsoft download center.

Is there a link to download the offline installer for SQL server 2019 express like what you do for 2017?



Thanks


Aggregate Table

$
0
0

Hi, 

I am using dummy data and hopefully I can explain what I am trying to do.

My current logic outputs the table below but given that it's only the one record, it's split into 3 rows due to Location being different for each.

Cust_No    Location      Location_North    Location_East    Location_South   Location_West

122           Newcastle            1                       0                        0                        0

122           Norwich              0                        1                        0                        0

122           Exeter                 0                       0                        1                        0

What I would like to see is a table that looks like this -

Cust_No      Location_North    Location_East    Location_South   Location_West

122                  1                          1                       1                     0

Any idea how I can do this please?

Rolling Date within Where Clause

$
0
0

Hi, 

I have a where statement below:

where start_date >=2017

Any idea how I can amend this please to say 

where start_date (rolling 36 months)

start_date formatted as YYYY-MM-DD

Doing PERSIST but column still Computed?

$
0
0

I installed SQL SERVER 2017 trial, I'm testing it as an ETL engine for data mining, executing with sqlalchemy. I ran into a PERSISTED problem when doing one-hot-encoding, trying to drop the original column after making the dummy columns: I couldn't, because even though I used PERSISTED, the columns are still Computed. It even takes longer to compute when compared to running the same code without PERSISTED, it seems like it does try to store... but then it doesn't store (??)..

So I tried doing something simple in SMS and still get the same 'bug', as seen below. Any ideas about what's going on? Thank you.

CREATE TABLE test (
  a INT,
  b INT,
);

INSERT INTO test 
    (a, b) 
VALUES 
    (1,2);

ALTER TABLE test ADD c AS a + b PERSISTED;
c shows up as (Computer, int, null)..


Install Bug SQL Server Express

$
0
0

HI guys,

I have downloaded the install for SQL2019 Expresss and when i open it, it is invisible on my desktop. I can move the window around but cannot see anything? Anyone had this issues? Im on Windows 10. When i download other installs they are fine except this one and its so bizzare!

Any help would be greatly appreciated!!

Thanks

James

after rebuild indexes also fragmentation still existing in table? Rebuild index in SQL Server does not reduce fragmentation

$
0
0

Hi All,
I have verified the fragmented tables before and after rebuild index job ,Rebuild index in SQL Server does not reduce fragmentation on tables.. Please help me to find , why it's not reduce fragmentation on tables and resolve the issue as well...

Thanks,

Ram




RAM

Viewing all 9243 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>