IT Nota

  • Home
  • How To
  • .NET
  • WordPress
  • Contact

Linked SQL Server Table Shows #Deleted in MS Access

When linking a SQL Server table (SQL Server 2008 R2) via ODBC, I encountered a major error where all cells in the table display #Deleted when opened from Microsoft Access 2010 (14.0.6123.5001).

Microsoft Access (linked SQL Server table) #Deleted error

The problem turns out to be that Microsoft Jet Database Engine maps bigint datatype to binary. One way to fix this is to clone the table and change the datatype from bigint to either int or (n)varchar. Changing the datatype in the original table just for this purpose is definitely not recommended.

If the table is used only as a reference then the solution is much simpler since it’s not necessary to edit or create new records. Instead of linking the table directly from MS Access, we can create a view that converts the datatype from bigint to a string (nvarchar) and link the view instead.

Create a plain view that selects all fields from the table.

CREATE VIEW dbo.vApplications
AS
SELECT CONVERT(NVARCHAR(25), Id) AS Id
      ,Employee
      ,EmpId
      ,CodeNumber
FROM dbo.Applications;

Then link the view from Access so we can see the data while the original table is untouched.

Microsoft Access (linked SQL Server View) with converted datatype

Further Reading

ACC2000: Linked SQL Server Table That Uses BigInt Data Type as Primary Key Displays #Deleted

August 28, 2013 Filed Under: How To Tagged With: Access, SQL Server

How to Get Month Number from Month Name and Year (T-SQL)

From a set of data in SQL Server database, we needed to find a way to quickly get a numeric representation (add a field MonthNo) of a month name in order to do a comparison. Given we only have a month name and year fields here’s a simple way to do it.

Original SQL:

SELECT [Id], [Month], [Year] 
FROM Table1

SQL Server: Query Result (Id, Month, Year)

Add a field called MonthNo:

MONTH(CONVERT(NVARCHAR, [Month]) 
	+ ' ' + CONVERT(NVARCHAR, [Year])
) AS MonthNo

Final SQL with the new column:

SELECT [Id]
	  , MONTH(CONVERT(NVARCHAR, [Month]) + ' ' 
	  + CONVERT(NVARCHAR, [Year])) AS [MonthNo]
	  , [Month], [Year] 	
FROM Table1

SQL Server: Query Result (Id, MonthNo, Month, Year)

Further Reading

MONTH (Transact-SQL)

August 8, 2013 Filed Under: How To Tagged With: Microsoft SQL Server, SQL, SQL Server

How to Calculate Duration Between Two Dates in T-SQL

A simple way to calculate the duration of a running program with a start and end time. The information should be presented in an hour:minutes:seconds format with leading zeroes (i.e., 00:00:00). Two local variables are used to demonstrate the query.

Typically, this is more useful if done as a stored procedure.

DECLARE @StartTime DATETIME = '2013-07-16 13:02:29';
DECLARE @EndTime DATETIME;
DECLARE @Duration INT;

SET @EndTime = '2013-07-16 15:29:31';

SET @Duration = DATEDIFF(second, @StartTime, @EndTime);

SELECT RIGHT('0' + CONVERT(VARCHAR(2), @Duration/3600), 2) 
   + ':' + RIGHT('0' + CONVERT(VARCHAR(2), @Duration%3600/60), 2) 
   + ':' + RIGHT('0' + CONVERT(VARCHAR(2), @Duration%60), 2) 
AS Duration;

The result here is printed with a column heading Duration and a value of 02:27:02.
SQL Server DateDiff Result

Further Reading

DECLARE @local_variable (Transact-SQL)
DATEDIFF (Transact-SQL)

July 16, 2013 Filed Under: How To Tagged With: Microsoft SQL Server, SQL, SQL Server

How to Copy Data from One Table to Another

A quick way to populate data from one table to another using Transact-SQL. The objective is to create a copy of the table and populating it at the same time and then create an SQL script to refresh the data when necessary. This can be achieved by using two similar SQL (three if we want to include the TRUNCATE command).

The first run we use “SELECT INTO” statement to query the source table and create a new table and populate it at the same time.

SELECT [ID]
      ,[System Manufacturer]
      ,[Computer Type]
      ,[Computer Model]
      ,[Name]
      ,[Serial Number]
      ,[Image]
      ,[OS]
      ,[OS Revision]
      ,[Architecture]
      ,[Primary User]
      ,[Domain]
      ,[Last Logon User]
      ,[Last Logon Domain]
      ,[Client Date] 
INTO [dbo].[DiscoveryAgentCopy] 
FROM [dbo].[DiscoveryAgent]
GO

You can use * if you want to copy all fields from the table.

SELECT * INTO [dbo].[DiscoveryAgentCopy] 
FROM [dbo].[DiscoveryAgent]
GO

If the copy table is already existed and we want to refresh only the data, we use “INSERT SELECT” statement to read the data from source and map them to the fields on destination table.

-- CLEAR COPY TABLE OF ALL DATA
TRUNCATE TABLE [dbo].[DiscoveryAgentCopy]
GO

-- POPULATE DATA
INSERT INTO [dbo].[DiscoveryAgentCopy] (
       [ID]
      ,[System Manufacturer]
      ,[Computer Type]
      ,[Computer Model]
      ,[Name]
      ,[Serial Number]
      ,[Image]
      ,[OS]
      ,[OS Revision]
      ,[Architecture]
      ,[Primary User]
      ,[Domain]
      ,[Last Logon User]
      ,[Last Logon Domain]
      ,[Client Date])
SELECT [ID]
      ,[System Manufacturer]
      ,[Computer Type]
      ,[Computer Model]
      ,[Name]
      ,[Serial Number]
      ,[Image]
      ,[OS]
      ,[OS Revision]
      ,[Architecture]
      ,[Primary User]
      ,[Domain]
      ,[Last Logon User]
      ,[Last Logon Domain]
      ,[Client Date]
FROM [dbo].[DiscoveryAgent]
GO

June 27, 2013 Filed Under: How To Tagged With: Microsoft SQL Server, SQL, SQL Server

How to Setup ODBC Connection

Launch Microsoft ODBC Data Administrator

On a 64-bit Microsoft OS, there will be two versions of Microsoft Open Database Connectivity (ODBC) Data Source Administrator tool (Odbcad32.exe) in two different locations:

  • %systemdrive%\Windows\SysWoW64 folder (32-bit)
  • %systemdrive%\Windows\System32 folder (64-bit)

The Odbcad32.exe file displays the following types of data source names (DSNs):

  • System DSNs (Visible to all users on the machine, including NT services)
  • User DSNs (Only visible to current user and can only be used on the current machine)

In this tutorial, we’re going to create a System DSN to an SQL Server Database.
ODBC Data Source Administrator

Click on Add button and select the latest SQL Server Native Client if possible (otherwise SQL Server will work just fine), click Finish. You can download the latest SQL Server Native Client (sqlncli.msi) from Microsoft® SQL Server® 2012 Feature Pack link.

Microsoft SQL Server Native Client 11.0 is installed when you install SQL Server 2016 (13.x).

ODBC Create New Data Source

This will bring up a new screen to setup SQL Server data source. Type in all the pertinent information for the SQL Server and click Next.

ODBC Create New Data Source to SQL Server

Enter the SQL Server user id and password to access the database.

ODBC SQL Server Data Source Authentication

Click Next two times and Finish and you should see the entry on the System DSN tab.

ODBC Data Source Administrator System DSN

Download

Microsoft® SQL Server® 2012 Feature Pack

Further Reading

ODBC Administrator tool displays both the 32-bit and the 64-bit user DSNs in a 64-bit version of Windows
SQL Server Native Client
Installing SQL Server Native Client

May 29, 2013 Filed Under: How To Tagged With: Microsoft, Microsoft SQL Server, SQL Server, Windows

« Previous Page
Next Page »
Buy me a coffee Support this site
Buy Me a Coffee?

Categories

  • .NET
  • Coding
  • Cybersecurity
  • Database
  • How To
  • Internet
  • Multimedia
  • Photography
  • Programming
  • Resources
  • Review
  • Tips and Tricks
  • Uncategorized
  • Use Case
  • WordPress
  • Writing

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Tags

.NET .NET Core AdSense ASP.NET Cdonts Dll Classic ASP Code Editor ETL FSharp Genesis Framework Git Google HP Asset Manager HTML5 Hugo IIS Information Security Internet Internet Information Services iOS JAMStack Linux macOS Microsoft Microsoft SQL Server MVC PHP PowerShell Python Simple Mail Transfer Protocol Smtp Server SQL SQL Server SSIS SSMS SSRS Sublime Text Visual Studio Visual Studio Code VPN Windows Windows 8 Windows 10 Windows 2012 Windows Server

Copyright © 2011-2025 IT Nota. All rights reserved. Terms of Use | Privacy Policy | Disclosure