Quantcast
Channel: Forum Getting started with SQL Server
Viewing all 7129 articles
Browse latest View live

How do i fix error 33222 ?

$
0
0
Doing SQL Server Auditing, I chose Security Log as my Audit Destination but when I am trying to enable the Audit I am getting error 33222. Can someone help me to resolve this problem ? 
I am using SQL Server 2012 on Windows Server 2012. 

What is schema

$
0
0

Hi, I'm a junior DBA, I want to learn much more about SQL server. Now I didn't get any clear explanation about SCHEMA. Can you please explain it easily with a simple example.


also the difference between mssql schema and mysql schema

MCSE - BI Career path

$
0
0

I want to achieve MCSE - BI certification, according to its path i need to pass all 5 papers.

70-461,70-462,70-463,70-466,70-467

I cleared 70-466 exam few month ago. When I am checking my certification activity, it is suggested that I have missed 70-461,70-462 and 70-463 exams. BecauseI already have MCSE - Data plateform 2012 certification and passed all 3 exams my questions are

Q1 Why I need to pass these exams again?

Q2 Can I upgrade MCSE - 2012 certification to MCSE - 2014 with exam codes?


Shamas Saeed (if Post helpful please mark as Answer) http://shamas-saeed.blogspot.com



How to update data from DataGridView with one column to database with two columns? ERROR - Cannot insert value NULL

$
0
0
I'm trying to update data from `DataGridView` to my database. While I was looking for the solution of this problem on google, I noticed that all of the solutions are managed by using class variables (for `DataTable`,`SqlDataAdapter`,...). I'm trying to do this just by using function variables.

This is how I loaded data to `DataGridView`:

   
private void LoadDataGridView(int ID)
{    try    {         SqlConnection connection = new SqlConnection(connString);         SqlCommand cmd = new SqlCommand("SELECT SENTENCE FROM Sentences WHERE CategoryID = @ID",connection);         cmd.Parameters.Add("@ID",SqlDbType.Int).Value = ID;         DataTable dataTable = new DataTable();         SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);         dataAdapter.Fill(dataTable);         DataGridView.DataSource = dataTable;    }    catch (Exception)    {         MessageBox.Show("ERROR WHILE CONNECTING TO DATABASE!");    }
}



`DataGridView` is showing just those sentences that match particular ID.

This is what I have tried so far:

 

private void RefreshBtn_Click(object sender, EventArgs e)   

{

try

{              SqlConnection connection = new SqlConnection(connString);              SqlCommand cmd = new SqlCommand("SELECT SENTENCEFROM Sentences WHERE CategoryID IN(@CategoryID)", connection);              cmd.Parameters.Add("@CategoryID",SqlDbType.Int).Value = CategoryID;              SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);              SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(dataAdapter);              dataAdapter.Update(dataTable);        }        catch (Exception)        {              MessageBox.Show("ERROR WHILE CONNECTING WITH DATABASE!");        }    }




This is the error that comes up:
>Cannot insert value NULL into column CategoryID, table ...;column does not allow nulls.Insert fails. The statement has been terminated.

  


Importing to SQL Server 2016

$
0
0

Hi, new to this...and limited experience of SQL Server and MS Access.

I am trying to import a database that I have created in MS Access 2016 into SQL Server 2016.

It appears that you are unable to import .accdb files into SQL Server and also unable to save a database created in Access 2016 as a .mdb file??

Anyone have any ideas ? - It's part of a college assignment and time is not on my side....I am trying to avoid a situation where I have to manually recreate the Tables in SQL Server.

Thanks.


SQL profiler event selection help

$
0
0
hi - 

can someone tell me what event selection property i have to select to only see SQL queries like insert, update and delete? My SQL Profiler is picking up everything and its too much.

Is filtering possible in Microsoft SQL AlwaysOn?

$
0
0

Hi All, 

Is it possible to exclude certain tables to be replicated/synchronized by AlwaysOn?

Thanks.

Sum up columns if duplicate records found

$
0
0

Hi All,

I wanted to mention a de - duplication logic which we are performing in our database. We are having some data in table1 and I want to apply de duplication logic if there is any duplicate data in table1.

E.G: I have the below data in table1

IDRollNumber1Number2Number3
1001507544
2001456899
2001659822
3001986531
4001583558
5001694764
5001358571
5002146525
6001361439
6002259954
7001146996

If ID & Roll are same for a record they will be treated as duplicate. In this example, ID 200 & Roll 1 and ID 500 and Roll 1 are duplicate. The logic is when the system finds duplicate records it will sum up Number1, Number2 & Number3 for duplicate records and only single(unique) row will be inserted into Table2. That means, the below data will take place in Table2.

1001507544
2001110166121
3001986531
4001583558
5001104132135
5002146525
6001361439
6002259954
7001146997


I want a single query which will show me that the duplicate records are inserted properly in Table2. For example, the query has to prepare in such a way so that it returns 0 if all the duplicate/non duplicate records are inserted properly in Table2. please let me know if it doesn't make sense.

Thank You in advance!!

 

JPP


SELECT...INTO - No error, but no table either!

$
0
0

Hello,

I am trying to create a table containing the results of a query with lots of JOINs. I'm using SELECT...INTO. The statement runs and tells me that the correct number of rows were affected, but it doesn't create the table. I'd like opinions on why it's failing.

The query runs properly and produces the expected results without the INTO clause.

My query is:

USE MarketingAnalysis_BAK
GO

ALTER DATABASE MarketingAnalysis_BAK SET RECOVERY BULK_LOGGED;
GO

IF OBJECT_ID('dbo.RawData_SteelPoles', 'U') IS NOT NULL
    DROP TABLE dbo.RawData_SteelPoles;
GO

SELECT   (a long series of columns)
INTO     dbo.RawData_SteelPoles
FROM     (a long series of joined tables)
GROUP BY (a long series of columns)
;
GO

ALTER DATABASE MarketingAnalysis_BAK SET RECOVERY FULL;
GO

-- Thanks in advance.

NOT EXISTS help with CTEs

$
0
0

I have code that I created that I want to get all the orders NOT ordered in a certain timeframe. I am using the following code:

SELECT

*

FROM

CL_OSQ_BLOCK

WHERE

notEXISTS

(select*fromtbl1

WHERECL_OSQ_BLOCK.ORDERSET_ID =

     

tbl1.PRL_ORDERSET_ID

My question is how can I get ALL the fields from tbl1 instead of or in addition to the fields from cl_osq_block?

Right now it runs, but only gives me the fields from whatever table I use before the subreport. I created a CTE- tbl1, that has all the fields I need but cant figure out how to get to them when using the not exists. 

FROM

CL_OSQ_BLOCK


WHERE

notEXISTS


   

(select*fromtbl1

WHERECL_OSQ_BLOCK.ORDERSET_ID =

          

tbl1.PRL_ORDERSET_ID

how to connect SQL server 2012 managemant studio using IP Address

$
0
0

Hi,

    I tried following steps.But i could not able to connect SQL Server management studio 2012 using ip address.I am using default instance name.

1.Enable TCP/IP connection & set TCP port 1433 in SQL server configuration manager.

2.Set firewall inbound & outbound rules to allow TCP & UDP port connection.

3.Allow the remote connection in SQL Server management studio 2012 also.

4.Enable Filestream property in the SQL server services of SQL server configuration manager.

I used to connect SQL Server management studio 2012 by giving server name as "ip address\defualt instance name" & Authentication as "SQL server Authentication" & username as "sa" & password.

Can anyone know the solution , let me know.

Thanks,

Priyankamurali

[SQL 2014] Pivot a date on a new column

$
0
0

Dear all,

I have a table with such data :

ColAColB colCMontant DateFrom

AAABBB CCC1234 2015-01-01

AAABBB CCC1278 2016-01-01

DDDEEE FFF7654 2015-01-01

HHHIII JJJ2861 2014-01-01

AAABBB CCC647 2014-01-01

DDDEEE FFF2931 2015-09-01

I need to have a result like this :

ColAColB colCMontant DateFromDateTo

AAABBB CCC1278 2014-01-012015-01-01

AAABBB CCC1234 2015-01-012016-01-01

AAABBB CCC647 2016-01-01NULL

HHHIII JJJ2861 2014-01-01NULL

DDDEEE FFF7654 2015-01-012015-09-01

DDDEEE FFF2931 2015-09-01NULL

If multiple lines with combination of colA, colB and ColC, then the DateFrom of second line must become the DateTo on first line

and null if not multiple line

Is there a way to do this ?

thanks in advance.

regards

SQL server Shutdown and start time on last 6 months

$
0
0

Hi, My management team wants a report of SQL server shutdown and startup times for last 6months, in my event log I have last 3 months records only. Please help me to get this done.

how to put if condition in where claues

$
0
0

HI guys,

I have one case .

I have 10 emp who have status=A

in that out of 10 we have 5 emp also having status= B

I that out of 5 we have 3 emp also  having Status = C

So i want only emp who have Status =A not in B OR C

AND Emp having Status BOTH (B,C)

Please give me the solution result will be 8 rows.

 

Declaring temp table produces Msg 1087 "Must declare the table variable"

$
0
0

Hello,

I have acquired a .sql script that creates a temporary table, populates it, and then uses it to populate a second table. It supposedly worked correctly before I received it. But now when I run it, I received an error message.

The script is as follows:

DECLARE @MaxThinning TABLE
  (
  CID int NOT NULL,
  LegConditionId int NOT NULL,
  InspectionID int NOT NULL,
  ThinningAmount numeric(5,2),
  CorrosionPresent bit NOT NULL
  );

  
--Select data into temp max thinning table    
INSERT INTO @MaxThinning
  (
  CID,
  LegConditionId,
  InspectionID,
  ThinningAmount,
  CorrosionPresent
  )
SELECT  dbo.OUS_LEGCOMPONENT.CID,
  dbo.OUS_LEGCOMPONENT.LegConditionId,
  dbo.OUS_LEGCONDITION.InspectionID,
  MAX(dbo.OUS_LEGCOMPONENT.OriginalThickness - dbo.OUS_LEGCOMPONENT.EffectiveThickness) as ThinningAmount,
  MAX(CAST(dbo.OUS_LEGCOMPONENT.CorrosionPresent as int))
FROM  dbo.OUS_LEGCOMPONENT INNER JOIN
  dbo.OUS_LEGCONDITION ON dbo.OUS_LEGCOMPONENT.CID = dbo.OUS_LEGCONDITION.CID
  AND
  dbo.OUS_LEGCOMPONENT.LegConditionID = dbo.OUS_LEGCONDITION.LegConditionID
GROUP BY dbo.OUS_LEGCOMPONENT.CID,
  dbo.OUS_LEGCOMPONENT.LegConditionId,
  dbo.OUS_LEGCONDITION.InspectionID
  ;
GO


IF OBJECT_ID('dbo.RawData_SteelTowers', 'U') IS NOT NULL
    DROP TABLE dbo.RawData_SteelTowers;
GO

--Create the final dataset; finish by joining to temp table to get max values
SELECT  (long list of columns),
  g.CorrosionPresent,
  g.ThinningAmount
INTO  dbo.RawData_SteelTowers
FROM  (list of tables) INNER JOIN,
  @MaxThinning g ON b.LegConditionID = g.LegConditionId
  AND
  b.CID = g.CID
GROUP BY (long list of columns),
   CorrosionPresent,
   ThinningAmount
;
GO

The message I get back is:

(54043 row(s) affected)

Msg 1087, Level 15, State 2, Line 34

Must declare the table variable "@MaxThinning".

My thought is that I AM declaring the table variable "@MaxThinning". But apparently it's not working. What am I missing?

Thanks.


NOT ABLE TO CREATE BACKUP OF FULL DATABASE OF SQL SERVER 2000

$
0
0

WHEN I BACKUP THE DATABASE IN SQL SERVER 2000, I AM NOT ABLE TO GET THE COMPLETE BACKUP. IN OTHE.R WORDS, WHEN I RESTORE THE BACKUP IN SOME OTHER COMPUTER, THE DATA I CAN SEE IS NOT COMPLETE.

SINCE MY DATA IS GROWING EVERY PASSING DAY AND THE DATABASE IS WORKING FINE, THEREFORE THE SIZE OF BACKUP SHOULD ALSO INCREASE EVERYDAY. BUT EVERY TIME I CREATE A BACKUP, THE SIZE OF BACKUP REMAINS THE SAME AND CONTAINS THE SAME DATA (WHEN I RESTORE IT IN SOME OTHER COMPUTER.

PLEASE GIVE A SOLUTION

THANKS 

RAJAN KAPOOR


Datawarehouse Building Snowflake schema or starschema

$
0
0

Hi Friends,

I have following tables in my datawarehouse. it is snowflake schema. i want too make it star schema. As solution what is better to add one column in fact table that reference to dimensionTransaction directly or remaing as it bellow? What is the best idea?


MS Certifications in SQL 2012

$
0
0
I am hoping to take 70-462 with Pearson UK. Having seen a few practice tests from 3rd party firms they are ALL multiple choice. Is this the case with the real life MS Sql Server exams? The MOS exams Ive just taken like Access, Excel Expert were simulations.

Joining two tables with no common column

$
0
0

There are two tables to be joined but there is no column column.

Table 1:-

It has the following columns in the image.

The 2nd table has the following columns:-

Now my question is in Table 1, there is a sql_count columns where there are list of sql count script listed. I executed each script by doing a union all and below is the result for that.

My question is, I need to put this result set in place of Sql_count columns and build a query in such a way which has, ID ( from table 1), Date (from table 2) , Name (from table 1), Type (from table 1), Description (from table 1), SQL_Count(From Union all query , Image 3) , SQL_impact(from table1), DataLink (From table 1). 

I have done a cross join which you can see in table 1. Please advice if its correct way. Can you guys please give me a query on this please?

Your inputs will help me a lot as I am new to this.

Thanks.


Karan Sheth

snapshot agent missing

$
0
0
Hi, I dropped transactional replication and trying to recreated it in lower environment. Scripted out publication script before dropping. I got below error.

Msg 14266, Level 16, State 1, Procedure sp_verify_schedule, Line 96
The specified '@freq_type' is invalid (valid values are: 1, 4, 8, 16, 32, 64, 128).

also created the subscription manually. but it did not start the snapshot automatically at end and received below error.Snapshot agent is missing

Could not find the regular snapshot job for the specified publication 'abcd'.
Supply either @job_id or @job_name to identify the job.
Changed database context to 'OLTP'. (Microsoft SQL Server, Error: 20678)

I tried below options but no luck. Please advise

Deleted the replication subscription and publication
ran sp_removedbreplication
disabled publishing for distributer and reconfigured the distributer
enabled the replication database
retried configuring replication but still snapshot agent is missing
Viewing all 7129 articles
Browse latest View live




Latest Images