sql-server

Deterministic scalar function to get day of week for a date

SQL Server, trying to get day of week via a deterministic UDF. Im sure this must be possible, but cant figure it out. UPDATE: SAMPLE CODE.. CREATE VIEW V_Stuff WITH SCHEMABINDING AS SELECT MD.ID, MD.[DateTime] ... dbo.FN_DayNumeric_DateTime(MD.DateTime) AS [Day], dbo.FN_TimeNumeric_DateTime(MD.DateTime) AS [Time], ... FROM...

Multiple Database Access with Delphi

I´m a 10 years FirebirdSQL user, and now i have a customer wanting to use MSSQL 2008. I don´t want to start flame wars with this, i just want your advice on data access tecnology. Im using Delphi MMVI. Use native ADO or DBExpress? Use third part? Any other words of wisdom? Thanks, yes i know that i will have to rewrite procedures, ...

How do I exclude Weekend days in a SQL Server query?

How do I exclude values in a DateTime column that are Saturdays or Sundays? For example, given the following data: date_created '2009-11-26 09:00:00' -- Thursday '2009-11-27 09:00:00' -- Friday '2009-11-28 09:00:00' -- Saturday '2009-11-29 09:00:00' -- Sunday '2009-11-30 09:00:00' -- Monday this is the result I'm looking for: d...

Are these tables too big for SQL Server or Oracle

Hey all, I'm not much of a database guru so I would like some advice. Background We have 4 tables that are currently stored in Sybase IQ. We don't currently have any choice over this, we're basically stuck with what someone else decided for us. Sybase IQ is a column-oriented database that is perfect for a data warehouse. Unfortuna...

SQL Server: How to generate object scripts without DMO/SMO?

i want to generate scripts for database objects, e.g. tables views stored procedures functions Since: SQL Server Management Objects (SMO) SQL Distributed Management Objects (SQL-DMO) (depricated) are not installed on a fresh install of: Windows XP Windows Vista Windows 7 nor are they redistributable, they are not an option (...

How can I store and query schedule data?

I'd like to allow my users to setup a schedule for their events. It could be a single day, or for convenience I'd like to allow them to specify a reoccurring event (similar to an Outlook appointment). For the single event it seems pretty easy (pseudo-code): Just have a DateOfEvent column that has the date on it. To grab future events:...

VB.NET: What is the equivalent of the SQL Server bit datatype?

I have a field in a SQL Server table that is of type bit. When I try to use a Boolean in VB.NET when passing parameters to a stored procedure, there are never any matches. I have also tried passing an integer to the stored procedure and that does not work either. ...

Update table SQL query help

I have a database student(attribute - studentid). studentid is a varchar. Now I want to add 'P' at the end of all studentids. 12 -> 12P 234 -> 234P What will be the sql query for this? ...

What is the easiest way to see which join is responsible for an entry not being shown

I have this db with lots of tables and frequently I have to answer the question: Why is entry x not being shown? Often I have an idea which entry might be the reason, but more often its wild guessing and trying. This gets boring after some time. Is there a tool out there where I enter the joins and the key of the entry that I want to ...

How do I query a view from SQL server with Perl and DBD::ODBC?

I can query the SQL server DB fine. The problem happens when I try and query a view. I'm not trying to do anything crazy: $sql = 'select * from location_v'; $stj = $db_destination->prepare($sql); It keeps dying on the prepare line. Here's what I'm getting back (which isn't all that useful): DBD::ODBC::db prepare failed: (DBD: st...

Weird SQL Server behavior

What´s the name of the behavior in the statement below? Create table dbo.Foo(name varchar(10)) insert dbo.Foo (name) select 'Weird' union select 'SQL' union select 'Server' union select 'behavior' declare @title varchar(max) set @title = '' select @title = name + ' ' + @title from dbo.Foo select @title --returns 'Weird SQL Server b...

Database patterns for partitioning large hierarchical datasets

Are there any best-pratices/patterns or general advice for partitioning large amounts of hierarchical data? Think of, say, a database of all the people in a given country and tracking who has worked with who. Thinking of the "person" entities in isolation, if a lot of data were to be kept about each person then a natural approach seems...

how can I add 2 digit together in SQL Server 2000

Hi, suppose I have a number 62. This is composed of 2 digits How can add 2 digit together divide by 10 and if result = something like 6.2 just take reminder declare @Number int,@Result int set @Number =62 if len(@Number) > 1 set @Result=????=--Add 6 and 2 =8 set @result=@result % 10 --Mod operator print @result -- the r...

Can I select all the tables with more than one update trigger

Can I select all the tables with more than one update trigger? The following code selects all the tables with more than one trigger, but I need only the tables with more than one update trigger. This query also returns tables with one insert trigger and one update one, which is not what I want. SELECT * FROM sys.triggers WHERE parent_id...

Save Sql Recordset into the csv file with well formatted?

I need to dump my sql query result into the text file. i have created the following query, DECLARE @cmd VARCHAR(2048) SET @cmd = 'OSQL -Slocalhost ' + ' -UCRN370 -PCRN370' + ' -Q"SELECT TOP 5 GageId FROM EwQMS370..msgages"' + ' -oc:\authors.csv' EXEC master..xp_cmdshell @cmd, NO_OUTPUT The ab...

Using Entity Framework with different version SQL Server

Hi all, I think most of you may work with the latest version of SQL Server and deploy it to the target machine which have a relative old version on it. Like using SQL Server 2008 on production machine and SQL Server 2005 on target server. While working in such situation with Entity Framework, It made me a little bit frustrated. I desig...

A list of all the SQL types and their .NET mapping?

I need a list of all the SQL types and their .NET (vb would be preferred, but C# also works for me) equivalent. ...

How to get the dependency of jobs in SQL Server?

Hi, How can we find the job dependency in SQL server. Therotically basing on the success of first one job the other job begins. Thanks a lot in advance!! ...

Performance tuning with SQL Server

Hi, I was trying to contact the author of a book I am reading on SQL Server query performance, but it seems the e-mail address provided in the book does not exis any more. So I decided to ask the community. I am pasting the messasge I had written below. Thanks in advance. ====== I have bought your book (SQL Server 2008 Query Performanc...

msdtc and isolation level

Hi, I need some clarification how MS-DTC will behave in scenario given below 1) I have more than one connection in within a transactionscope (Isolation level - ReadCommited),which will bring MS- DTC into action now : a) Will MS-DTC automatically change isolation level to SERIALIZABLE. b) (Imp) If above answer is yes and I have imple...