I have written SQL statements (stored in a text document) that load data into a SQL Server database. These statements need to be repeated daily. Some of the statements use the NewId()
function to populate a keyed field in the database, and this works fine. While I'm in the process of writing an application to replicate these statements, I want to use Access queries and macros instead of copying and pasting queries into SQL Server, thus saving me time on a daily basis. All is working fine but I can't find any function that will replace the SQL NewId()
function. Does one exist or is there a work around? I'm using SQL Server 2005 and Access 2007.
相关问题
- keeping one connection to DB or opening closing pe
- Importing data from MS Access db to PostgreSQL db
- DoCmd.TransferSpreadsheet is not recognizing works
- Is there a way to apply theme on converted access
- Quickest method for matching nested XML data again
相关文章
- Convert column to string in SQL Select
- COALESCE, IFNULL, or NZ() function that can be use
- CurrentDb.RecordsAffected returns 0. Why?
- How to embed ms-access forms in C# module?
- Why not “Invalid column name XYZ” error in subquer
- Sleep Lib “kernel32” gives 64-bit systems error
- Create @TableVariable based on an existing databas
- How to destroy an object
On top of matt's answer, you could simply use a pass-through query and just use your existing, working queries from MS Access.
Again, there seems to be confusion here.
If I'm understanding correctly:
You have an Access front end.
You have a SQL Server 2005 back end.
What you need is the ability to generate the GUID in the SQL Server table. So, answers taht suggest adding an AutoNumber field of type ReplicationID in Access aren't going to help, as the table isn't a Jet table, but a SQL Server table.
The SQL can certainly be executed as a passthrough query, which will hand off everything to the SQL Server for processing, but I wonder why there isn't a default value for this field in SQL Server? Can SQL Server 2005 tables not have NewId() as the default value? Or is there some other method for having a field populate with a new GUID? I seem to recall something about using GUIDs and marking them "not for replication" (I don't have access to a SQL Server right at the moment to look this up).
Seems to me it's better to let the database engine do this kind of thing, rather than executing a function in your SQL to do it, but perhaps someone can enlighten me on why I'm wrong on that.
A solution would be to insert the stguidgen() function in your code, as you can find it here: http://trigeminal.fmsinc.com/code/guids.bas
The only workaround I can think of would be to define the column in your access database of type "Replication ID" and make it an autonumber field. That will automatically generate a unique GUID for each row and you won't need to use newid() at all. In SQL server, you would just make the default value for the column "newid()".