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

RIght Outer Join not working as expected

$
0
0

I have selected two record groups (217,244) and want to perform a query that will list all the records, whether matching or not. What am I doing wrong? I cannot get recid=4 to show in the result set.

Create Table ImportLog
( recid int,
  grouploadid int,
  groupid int,
  tablename varchar(128),
  note varchar(500)
  )

  Insert Into ImportLog
  Values
  (1,216,1,'tableb','noteb'),
  (2,217,1,'tablea','notea'),
  (3,217,2,'tableb','noteb'),
  (4,217,3,'tabled','noted'),
  (5,230,1,'tableb','noteb'),
  (6,244,1,'tablea','notea'),
  (7,244,2,'tableb','noteb'),
  (8,244,3,'tablec','notec')
select 	r1.RecID, r1.GroupLoadID, r1.groupid, r1.tablename, r1.note,
		r2.RecID, r2.GroupLoadID, r2.groupid, r2.tablename, r2.note
	from ImportLog r1
		--left outer join  -- shows record 8
		-- right outer join -- will not show record 4
		full join -- shows record 8, will not show record 4
			(select RecID, GroupLoadID, groupid, tablename, note
				from ImportLog
				where GroupLoadID = '217'
			) r2
		on r1.TableName = r2.TableName	and r1.Note = r2.Note and r1.Groupid = r2.Groupid
	  where r1.GroupLoadID = '244'
	  order by 1


Is there a way to get long running SQL Agent jobs information using powershell?

$
0
0

Hi All,

Is there a way to get long running SQL Agent jobs information using powershell for multiple SQL servers in the environment?

Thanks in Advance.

--Hunt

Unable to login to sa account

$
0
0

Hi,

I inherited database admin duties from a previous employee who is no longer with us. The program currently used is SQL Server Manager and it has a database that I need to back up. Problem is, he never left the password. I have tried all combinations I could think of and doesn't help. I have tried to login as local administrator but this fails.

I can login with Windows Auth but this doesn't give me the ability to do anything.

What are my options? At this point when I have to run DB repairs etc I just have our Windows guy take a snapshot of the VM. I rather be able to backup to disk or some other storage but this requires the sa account.

IT Tech

How to update Junction Table

$
0
0

I have trigger setup on the sql server end, which inserts data into the tables products and prices, however my junction table 'Product_Prices', is not automatically updating with the records, when the trigger is executed. 

Here is my database table schema:

Products
(
Product_id [pk]
Product
type
UploadDate
)Prices
(
Price_id [pk]
price
uploadDate
)Product_Prices
(
Product_id REFERENCE Products (Product_id)
price_id REFERENCE prices (price_id)
Foiergn KEY (Product_id, price_id)
Note
)

Is my structure incorrect or am I missing something?

Please advice. 

Many thanks for your time and help. 

which index will it take and why ?

$
0
0

Hi, 

I have a table Employee and i have an index on EmpID on this table. Now i have created a view EmpView on this table. I have created an index on this view for the same column EmpID.

Now my question is If i query select * from Empview where empId = something then which index will it consider and why?? 

Thanks in advance

Balaji 


Balaji - BI Developer

Calculating fractions of hours from time date range

$
0
0
Hello friends,

I'm using sql server 2008 r2 and I have a table called attendance with the following fields

attendance_no    int
attendance_date    date
attendance_timein    time(7)
attendance_timeout    time(7)
emp_id    int   

and another table called employee with the following fields
emp_id int
emp_name  varchar(50)
emp_tel  varchar(50)

I need to calculate the total minutes worked as well as total hours worked for each employee with in a specified date range and I created the below query which working fine but it is not calculating the  fractions of hours, I mean when an employee works for example 7 and half hours, its showing just 7 hours instead of 7.5 hours.

SELECT a.attendance_date As 'Date',e.emp_id As 'ID',e.emp_name As 'Name',e.emp_tel As 'Telephone',left(a.attendance_timein,8)[Time in],left(a.attendance_timeout,8)[Time out],
   
   + CAST(DATEDIFF(second, attendance_timein, attendance_timeout) / 60 AS NVARCHAR(50)) As 'Total minutes',
   CAST(DATEDIFF(second,attendance_timein,attendance_timeout) / 60 /60 % 60 AS NVARCHAR(50)) As 'Total hours'

    from attendance a join employee e on e.emp_id=a.emp_id and a.attendance_date between '2014-11-06' and '2014-11-08'  and e.emp_tel='65098009'

I would appreciate any help about this.

Thanks in advance

Mohamoud

Transactional Server Replication

$
0
0

Hi,

I created Publisher on instance "A" and Subscriber on instance "A/alternate".

Strange thing is that replication copy all tables but without data... Here is a error that occurs, can anybody suggest what to do in this situation?

Error:

CREATE TABLE [Sales].[Customer](
    [CustomerID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
    [PersonID] [int] NULL,
    [StoreID] [int] NULL,
    [TerritoryID] [int] NULL,
    [AccountNumber]  AS (isnull('AW'+[dbo].[ufnLeadingZeros]([CustomerID]),'')),
    [rowguid] [uniqueidentifier] ROWGUIDCOL  NOT NULL,
    [ModifiedDate] [datetime] NOT NULL
)


(Transaction sequence number: 0x000000D100001D4400CE00000000, Command ID: 289)

Error messages:
Cannot find either column "dbo" or the user-defined function or aggregate "dbo.ufnLeadingZeros", or the name is ambiguous. (Source: MSSQLServer, Error number: 4121)
Get help: http://help/4121
Cannot find either column "dbo" or the user-defined function or aggregate "dbo.ufnLeadingZeros", or the name is ambiguous. (Source: MSSQLServer, Error number: 4121)
Get help: http://help/4121

Adding numbers from text onto a date

$
0
0

Hi lifesavers!

I am writing a report where my people have used a text field to state the number of days for an audit to last.

I am trying to develop a schedule that shows AUDIT START DATE + number of days in text field (can range from .5 - 30), but I cant get SSRS to recognize the text as a number to add to the date.

I have tried to use:

=Fields!AuditStartDate.Value + Val(Fields!AuditDays.Value)

But this comes up with an error. All I need to be able to do is add the number written in a txt field to the audit start date which will give me a planned audit end date.

Can anyone please help me?

Thanks :)


Installation of SQL Server device client accesses

$
0
0

Hello,

Please help me out for the below query.

Actually I don't have an idea of User & Device CAL Licenses. I joined newly in a company as SQL DBA but I don't know about the licensing part. So, In my present company they are having SQL Server 2008 R2 Standard Edition with 5 SQL Device CAL's. I need to install device CAL's for the Developers. I had checked in Licensing details. So, it is showing 5 SQL Device CAL's. When I go to download it is showing many files and basically it is not showing the CAL application. I need to know which file exactly I should download and install. All applications are showing the same but it is not confirming about the device CAL Application.

Kindly let me know which file I need to download and install and how to manage device cal licenses. I searched in internet a lot but I didn't found the correct answer.

Thanks

Sainath 

Wildcard certificate in mssql 2008R2

$
0
0

Hello, 

I have installed wildcard certificate in Certificates(Local Computer)\Personal in  sql server. We are using Windows 2008R2 server and 2008 R2 SQL server. Certificate is issued by StartCom. With certificate everything is ok (I have used it in IIS), but it didnt appeared in sql configuration manager protocols dropdown list. So i followed microsoft article:

http://support2.microsoft.com/kb/316898

and added certificate thumbrint in registry. Restarted SQL service.

Then I am trying to connect to sql server using SMSS I am getting error:

"A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 0 - The certificate's CN name does not match the passed value.) (Microsoft SQL Server, Error: -2146762481)"

So obviously problem is wildcard certificate, because it is issued to *.domain.com and server name is server.domain.com.

By this article, microsoft sais that "SQL Server 2008 R2 and the SQL Server 2008 R2 Native Client support wildcard certificates."

http://technet.microsoft.com/en-us/library/ms189067(v=sql.105).aspx

So question would be: Sql 2008 r2 supports or does not support wildcard certificates. If supports, so there is problem? Why i am getting this error?


Mantas

column store index and table designer

$
0
0

Is it possible to create a column store index using table designer , not code?

thanks


sukai

Importing schema+ data using a text file containing sql commands

$
0
0

I have the 2012 SQL SVR Mgmt Studio installed. I received a file--snippet below... from an export of our current DB provider, Advantage. I know I have to edit a lot of commands, but my question is quite simple--how do I use a text file with commands in it like below to create tables, columns and load data into SQL SVR.

---data.txt file contents----

-- Table Type of Beneficiary is ADT
Create Table Beneficiary(
   PlanId Char( 9 ),
   Hash Integer,
   Line1 Char( 128 ),
   Line2 Char( 128 ),
   Batch Char( 16 ) );

EXECUTE PROCEDURE sp_CreateIndex90( 'Beneficiary', 'LAC_LACV1_Beneficiary.adi', 'KEY1', 'Hash;PlanId', '', 2051, 4096, NULL );

INSERT INTO "Beneficiary" VALUES( 'LACV1', 983, 'Judith Pursifull~Spouse~100~~~', 'Michael Pursifull~Son~50~Thomas Pursifull~Son~50', '761011042' );
INSERT INTO "Beneficiary" VALUES( 'LACV1', 996, 'Anna Brownlow~Spouse~100~~~', 'Kaitlin Brownlow~Daughter~85~Lawanda Brownlow~Mother~15', '49036615' );
INSERT INTO "Beneficiary" VALUES( 'LACV1', 1005, 'Weldon Shelton~Other~50~Star Shelton~Other~50', 'Danica Shelton~Sister~50~Ryan Shelton~brother~50', '109075816' );
INSERT INTO "Beneficiary" VALUES( 'LACV1', 1031, 'Donald D Duffy~Spouse~100~~~', 'Brandon M Duffy~Son~100~~~', '219979254' );
INSERT INTO "Beneficiary" VALUES( 'LACV1', 1063, 'Lynne Roffino~Other~50~John Roffino~Other~50', 'Katy Roffino~Sister~50~Margaret Roffino~Sister~50', '604232358' );
INSERT INTO "Beneficiary" VALUES( 'LACV1', 1062, 'John Teaven Redstone~Spouse~100~~~', '~~~~~', '482024691' );
INSERT INTO "Beneficiary" VALUES( 'LACV1', 1032, 'Judith Anne Brown (for cat care)~Other~50~Judith Ann (Kappler) Barklage~Other~50', 'LaVerne Cocke (for cat care)~Friend-PantegoBibl~50~~~', '358324107' );

-- Table Type of Date is ADT
Create Table Date(
   Hash Integer,
   PlanId Char( 9 ),
   Type Char( 24 ),
   Date Date,
   Override Logical,
   Batch Char( 32 ) );

EXECUTE PROCEDURE sp_CreateIndex90( 'Date', 'LAC_LACV1_Date.adi', 'KEY1', 'Hash;Date;PlanId;Type', '', 2051, 4096, NULL );

INSERT INTO "Date" VALUES( 1018, 'LACV1', 'HARDSHIPEND', '2010-02-20', False, '20090820-9414719' );
INSERT INTO "Date" VALUES( 1018, 'LACV1', 'HARDSHIPSTART', '2009-08-20', False, '20090820-9414719' );
INSERT INTO "Date" VALUES( 1001, 'LACV1', 'HARDSHIPEND', '2010-02-06', False, '20090806-9371968' );
INSERT INTO "Date" VALUES( 1001, 'LACV1', 'HARDSHIPSTART', '2009-08-06', False, '20090806-9371968' );
INSERT INTO "Date" VALUES( 1022, 'LACV1', 'LUMPSUMDISTRIBUTION', '2009-07-21', False, '20090721-9337640' );


charles.leggette

Listing Size of all user Databases in SQL2005

$
0
0
Can anyone please tell me of a way of generating a list of all user databases and their size with one command or view?

Thanks,

Cannot Log in locally to SQL Server 2008 R2 SP2, Can log in remotly.

$
0
0

Hello, Domain Admins has been added to the sysadmin group.  My domain account is a member of Domain Admins.  I can log into the database engine via Managment Studio from a remote computer however i cannot log into the Managment Studio locally on the server unless i add my actual account  to Security > Logins.  

Running on Windows Server 2012 Std.

Your help is appriciated.


How to find instance name

$
0
0

Hi

 

I just start to learn SQL server now. I am trying to migrate data from oracle to SQL server 2005 using SQL server migrant assistant for Oracle.  But I don't know how to fiill this connection details

 

 

SQL Server host:

<ServerHost>

SQL Server port
(leave empty if default):

<8888>

SQL Server instance name
(leave empty if default):

<your_instance>

Target database:

<your_db_name>

Target schema:

dbo (by default)

User name:

<your_username>

Password:

<your_password>

 

How to find these properties?  Anyone can help?

 

Thanks

 

Li

 


how much memory each instance is currently using during the business day

$
0
0

how to find out how much memory each instance is currently using during the business day?

Thanks in advance.

xp_logevent permission

$
0
0

Hi,

I am getting below error

The SELECT permission was denied on the object 'ServiceAgent', database 'HOFHUB', schema 'dbo'. 

The EXECUTE permission was denied on the object 'xp_logevent', database 'mssqlsystemresource', schema 'sys'.

Can anyone please help how to solve it?

Thanks

Store stored procedure values in temp table

$
0
0

I am using stored procedure to get the values but column headers are not fixed..since I am using pivot function.

So is it possible to create temp table according to the random header and store values to temp table


Abhinav

SSDT/VisualStudio requirements for SQL Server 2014

$
0
0

Hi

What is the minimum version of SSDT (VS Shell) is required for the creation of BI solutions in SQL Server 2014?

I have VS2010 (was installed from SQL Server 2012 installation media) but this will not work with SQL Server 2014.


Export data using stored procedure to excel

$
0
0

How to export and save data from SQL Server to MS Excel using stored procedure.

Thanks in advance


Abhinav

Viewing all 8979 articles
Browse latest View live


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