sql-server

Avoid Database Cursor in SQL Server

I have a bit of a puzzle (at least for me) which I am hoping is mostly because I am not yet an SQL master of the universe. Basically I have three tables: Table A, Table B, and Table C. Table C has a FK (Foriegn Key) to Table B, which has FK to Table A. (Each of these is many to one) I need to remove an entry from Table A and of cours...

Adding triggers and tables to MBS databases

Hi all, does anyone have experiences whether it's possbile to add triggers and custom tables to MBS systems? To be more exact: I want to add a trigger and table to a Microsoft CRM installation in order track several changes to some records in the system. Is that a possible way to go or are there any technical / legal issues which make ...

How do I update n rows in a table?

I need to update the first N rows in a table meeting a condition. I know I can do an Update Top N... but the problem is that N is in a @variable. UPDATE TOP @N SET ... doesn't work. Is there a way to do this that I am just missing? No specific table definitions here because it doesn't matter what the columns are.. If I can do it for...

Dynamically update one parameter based on the value of another

We have a report in SSRS 2005, where in we wanted to update one parameter(which is not linked to any other report parameters or dataset) based on the value of another report parameter(which is the selected value from a dataset). Can anyone let me know how to achieve this functionality? ...

Memory effective way to read BLOB data in C#/SQL 2005

What's the most memory effective way to read an SQL 2005 image field using C# 3.5? Right now I have a (byte[])cm.ExecuteScalar("..."). If I could not read all field content into memory, that would be nice. ...

Create SQL Server Compact database file programmatically

How can I create a new SQL Server Compact database file (.sdf) programmatically, without having an existing template file to copy from? ...

datetime in bigint field

I am trying to add a date time to a bigint field and then display it in a gridview using SQL query... First im not sure how to add the date time in big int field so im using long s= DateTime.Now.Ticks; which is storing a sample value like 633896886277130000 then i want get only the date from it using the SQl Select statement and di...

IF EXISTS, THEN SELECT ELSE INSERT AND THEN SELECT

How do you say the following in Microsoft SQL Server 2005: IF EXISTS (SELECT * FROM Table WHERE FieldValue='') THEN SELECT TableID FROM Table WHERE FieldValue='' ELSE INSERT INTO TABLE(FieldValue) VALUES('') SELECT TableID FROM Table WHERE TableID=SCOPE_IDENTITY() END IF What I'm trying to do is to see if there is a blank fie...

SQL Server Database Restore Hourly

Hi I run a software platform and am thinking of setting up a demo site so that people can login into a pretend site and edit the data, etc... However I want then the database to 'reset' every 'x hours / days' is there a way sql server can do this itself? Otherwise I will have to code an application to restore all the table data and th...

Object Relational Features of SQL Server

Does anyone know a good reference to look into what Object Relational features are available in SQL Server (any version)? I found a really good summery for Oracle but all I can find for SQL Server is information about LINQ to SQL, which is good stuff, but I'm looking for more power in the database like defined types, nested tables, etc. ...

How can I create two temporary tables with the same structure without write twice?

How can I create two temporary tables with the same structure without write twice? Something like that: DECLARE @TEST_TABLE1, @TEST_TABLE2 TABLE ( FIELD1 INT, FIELD2 INT ) and NO: DECLARE @TEST_TABLE1 TABLE ( FIELD1 INT, FIELD2 INT ) DECLARE @TEST_TABLE2 TABLE ( FIELD1 INT, FIELD2 INT ) ...

How can I convert ticks to a date format?

I am converting a ticks value to a date like this: Convert(datetime, (MachineGroups.TimeAdded - 599266080000000000)/864000000000); Using this i get: 9/27/2009 10:50:27 PM But I want just the date in this format: October 1, 2009 My sample ticks value is 633896886277130000 What is the best way to do this? ...

How do I make an asp.net installer that includes sql database and data?

The Sql Server 2008 is on a different server than the web server, and I cannot install directly to web server from visual studio box. I can only ftp files to the web server, then copy/execute files once logged on to web server. ...

SQL server - schema

We can see schema for all tables and views by: SELECT * FROM INFORMATION_SCHEMA.TABLES SELECT * FROM INFORMATION_SCHEMA.VIEWS Can we view schema for stored procedures or functions through tsql? ...

Move Data from Oracle to SQL Server

I would like to copy parts of an Oracle DB to a SQL Server DB. I need to move the data because the Oracle box is being decommissioned. I only need the data for reference purposes so don't need indexes or stored procedures or contstaints, etc. All I need is the data. I have a link to the Oracle DB in SQL Server. I have tested the f...

SQL Statement(s)

If I have the following table: CREATE TABLE #temp ( id int, num int, question varchar(50), qversion int ); INSERT INTO #temp VALUES(1, 1, 'Question 1 v1', 1); INSERT INTO #temp VALUES(2, 1, 'Question 1 v2', 2); INSERT INTO #temp VALUES(3, 2, 'Question 2 v1', 1); INSERT INTO #temp VALUES(4, 2, 'Question 2 v2', 2); INSERT...

How do I fix this SQL statement to AVG muliple rows from another table?

I am having a few issues with the below SQL. SELECT * FROM (SELECT tbrm_Article.ArticleID, tbrm_Article.CountryID, tbrm_Article.CategoryID, tbrm_Article.Title, tbrm_Article.ArticleDetail, tbrm_Article.Source, tbrm_Article.ArticleDateTimeAdded, ...

Performing multiplication in SQL SERVER(SET BASED APPROACH)

Suppose I have a table like the following: tblNumbers Numbers 4 5 3 6 Using SET BASED approach how can I perform a multiplication so the output will be: Output 360 N.B~ There is no hard and fast rule that there will be only four numbers, but I'd prefer the answer to be using a CTE and/or correlated subquery. ...

How to display all the dates between two given dates in SQL

Using SQL server 2000. If the Start date is 06/23/2008 and End date is 06/30/2008 Then I need the Output of query as 06/23/2008 06/24/2008 06/25/2008 . . . 06/30/2008 I Created a Table names as Integer which has 1 Column, column values are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 then I used the below mentioned query Tried Query SELECT DATEADD...

Why the result of exp/log of Postgres differs from SQL Server?

I don't have SQL Server on my box, but why won't the following answer return 360 on Postgres? select exp(sum(log(val))) from (values(4),(5),(3),(6)) as tbl(val) returns 12.888075 ...