sql-server

Get Asp.Net username from SQL Server 2008?

With windows and sql server accounts, I can access the logged in user with functions like: user_name() or suser_sname(). Can I access the user that is logged into asp.net in the same way? ...

Check if a string contains a substring in SQL Server 2005 Stored Procedure

Hello I've a string @mainString = 'CATCH ME IF YOU CAN'. I want to check whether the word 'ME' inside @mainString. So how to check if a string has a substring in sql? Thank you Regards NLV ...

What is the fastest method to create a new database from a template ?

We are creating databases on demand and the databases can be created from different templates. All templates have the same structure but different data. The data contained by the templates is small. What is the fastest way to create a copy of the database: Backup/Restore Using T-SQL ? Using SMO ? Create a new database from a scripte...

Group / User based security. Table / SQL question

Hi, I'm setting up a group / user based security system. I have 4 tables as follows: user groups group_user_mappings acl where acl is the mapping between an item_id and either a group or a user. The way I've done the acl table, I have 3 columns of note (actually 4th one as an auto-id, but that is irrelevant) col 1 item_id (item...

DNN 5.2.3 Stored Procedures executing numerous times during page loads

After tracing the DB activity from a DNN 5.2.3 site I noticed that there are numerous identical calls to the database whilst loading the home page for the first time (afterwards the caching works successfully). //Procedure : Number of executions exec dbo.aspnet_Membership_GetUserByName @ApplicationName=N'DotNetNuke',@UserName=N'MYDOMAI...

Database Testing

Can anyone expalin in detail how to perform Database Testing. I've basic idea about DDL, DML statements. ...

How to determine whether a database has been changed or not ?

I have a need to determine if a database on a MS SQL Server has changed between two distinct moments. The change can be structural or data-related and the check should be generic (i.e. independant of the structure of the database). Preferably, I'd like the check to be T-SQL based or with SMOs, not file based. I checked on MSDN but I hav...

Row concat from this query

I have this query: SELECT DISTINCT IM.EDIFICIOS_ID, TI.TITULAR FROM IMPORTACION IM INNER JOIN I_EDIFICIO IE ON IM.IMPORTACION_ID=IE.IMPORTACION_ID INNER JOIN I_EDIFICIO_TITULAR ET ON IM.IMPORTACION_ID=ET.IMPORTACION_ID AND IE.EDIFICIO_ID=ET.EDIFICIO_ID INNER JOIN I_TITULAR TI ON IM.IMPORTACION_ID=TI.IMPORTACION_ID AND ET.TITULAR_ID=TI.T...

Login faild for user 'SOFTWARE\Soft'

Cannot open database "SystematicDBSearch" requested by the login.Login faild for user 'SOFTWARE\Soft'.Where is a problem. ...

How should extremely large tables in SQL SERVER be indexed?

We have a large table (450 million rows containing 34 columns of numeric or datetime data) that currently has around a dozen recommended paths for querying. The table currently has 17 indexes and I have no authority to change the structure of this table, though I am able to provide indexing strategies. The first problem I see is that t...

How to get identities of inserted data records using SQL bulk copy

I have an ADO.NET DataTable with about 100,000 records. In this table there is a column xyID which has no values in it, because the column is an auto-generated IDENTITY in my SQL Server database. I need to retrieve the generated IDs for other processes. I am looking for a way to bulk copy this DataTable into the SQL Server database, an...

NHibernate is not connecting to sql server.

When i set up a regular connection, it works, however when i try to use nhibernate, hibernate.cfg.xml, i m getting the following error. Message="A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and...

Getting the sum of a datediff result

Hi I have a SQL statement (MS SQL Server 2005) that does a simple calculation of the differences in dates on a few records. I want to return the total/sum of the DATEDIFFs too. SELECT (DATEDIFF(day, StartDate, EndDate)+1) AS myTotal FROM myTable WHERE (Reason = '77000005471247') How do I get the SUM from myTotal? Tha...

Many to Many Association Tables - Is it customary to put additional columns in these tables?

We've encountered the following situation in our database. We have table 'A' and table 'B' which have a M2M relationship. The association table is named 'AB' and contains a FK column to table 'A' and a FK column to table 'B'. Now we've identified a need to store additional data about this association. For example, a date when the associa...

How to apply Data Mining (Association Rule) to a huge database ?

Hello What I want to do is to apply Association method of data mining on my SQL Server 2000 database. Association rule is something like "finding the most frequent items that appear together in database." For those who don't know or who want to remember what is association method is like, take a look at this presentation about Associa...

How to get only the date from the sql server

this is what i want. but i have put only a specified date. SELECT BookName, Author, BookPrice FROM Book WHERE Book.Book_ID = ( SELECT Book_ID FROM Temp_Order WHERE Temp_Order.User_ID = 25 AND Temp_Order.OrderDate='3/24/2010' ) this is the date function i used. but it takes the time also. how to stop it. please help m...

In SQL Server what is most efficient way to compare records to other records for duplicates with in a given range of values?

We have an SQL Server that gets daily imports of data files from clients. This data is interrelated and we are always scrubbing it and having to look for suspect duplicate records between these files. Finding and tagging suspect records can get pretty complicated. We use logic that requires some field values to be the same, allows som...

How to migrate large amounts of data from old database to new

I need to move a huge amount of data from a couple tables in an old database to a couple different tables in a new database. The databases are SQL Server 2005 and are on the same box and sql server instance. I was told that if I try to do it all in one shot that the transaction log would fill up. Is there a way to disable the transaction...

Difference between dates when grouping in SQL

I have a table of purchases containing a user_id and a date_of_purchase. I need to be able to select all the users who have made 2 purchases within 12 months of each other. The dates can be any point in time as long as they are less than 12 months apart. e.g. user_id date_of_purchase 123 01/Jan/2010 124 01/Aug/...

How to get parameter values for dm_exec_sql_text

I'm running the following statement to see what queries are executing in sql server: select * from sys.dm_exec_requests r cross apply sys.dm_exec_sql_text(r.sql_handle) where r.database_id = DB_ID('<dbname>') The sql text that comes back is parameterized: (@Parm0 int) select * from foo where foo_id = @Parm0 Is there any way to get ...