Search Results

Search found 1100 results on 44 pages for 'dbo'.

Page 36/44 | < Previous Page | 32 33 34 35 36 37 38 39 40 41 42 43  | Next Page >

  • T-SQL Getting duplicate rows returned

    - by cBlaine
    The following code section is returning multiple columns for a few records. SELECT a.ClientID,ltrim(rtrim(c.FirstName)) + ' ' + case when c.MiddleName <> '' then ltrim(rtrim(c.MiddleName)) + '. ' else '' end + ltrim(rtrim(c.LastName)) as ClientName, a.MISCode, b.Address, b.City, dbo.ClientGetEnrolledPrograms(CONVERT(int,a.ClientID)) as Abbreviation FROM ClientDetail a JOIN Address b on(a.PersonID = b.PersonID) JOIN Person c on(a.PersonID = c.PersonID) LEFT JOIN ProgramEnrollments d on(d.ClientID = a.ClientID and d.Status = 'Enrolled' and d.HistoricalPKID is null) LEFT JOIN Program e on(d.ProgramID = e.ProgramID and e.HistoricalPKID is null) WHERE a.MichiganWorksData=1 I've isolated the issue to the ProgramEnrollments table. This table holds one-to-many relationships where each ClientID can be enrolled in many programs. So for each program a client is enrolled in, there is a record in the table. The final result set is therefore returning a row for each row in the ProgramEnrollments table based on these joins. I presume my join is the issue but I don't see the problem. Thoughts/Suggestions? Thanks, Chuck

    Read the article

  • Copy new records from datatable and identify changes in old records

    - by Betite
    Assume there are two tables: Remote_table and My_table. Remote_table has 6 columns: **PROJECT JOB_TYPE MONTH YEAR** HOURS IS_DELETED 134393 70 1 2013 30 0 134393 70 2 2013 50 0 134393 70 3 2013 80 0 134393 70 10 2012 10 0 134393 70 11 2012 0 0 134393 70 12 2012 15 0 My_table is a copy of remote_table. I tried to copy only the new records from the remote_table by this query: SELECT * FROM [remote_DB].[LudanProjectManager].[dbo].Remote_table EXCEPT SELECT * FROM My_table It works OK but I get a duplicate primary key exception when changes have been made on the remote_table on the hours column. Can anyone think of a way to copy only the new records from remote_table and if changes has been made on old records, to identify them and update the my_table to correspond?

    Read the article

  • T-SQL Add Column In Specific Order

    - by Aren B
    Im a bit new to T-SQL, Coming from a MySQL background Im still adapting to the different nuances in the syntax. Im looking to add a new column AFTER a specific one. I've found out that AFTER is a valid keyword but I don't think it's the right one for the job. ALTER TABLE [dbo].[InvStockStatus] ADD [Abbreviation] [nvarchar](32) DEFAULT '' NOT NULL ; This is my current query, which works well, except it adds the field at the end of the Table, Id prefer to add it after [Name]. What's the syntax im looking for to represent this?

    Read the article

  • Why does SQL Server 2000 treat SELECT test.* and SELECT t.est.* the same?

    - by Chris Pebble
    I butter-fingered a query in SQL Server 2000 and added a period in the middle of the table name: SELECT t.est.* FROM test Instead of: SELECT test.* FROM test And the query still executed perfectly. Even SELECT t.e.st.* FROM test executes without issue. I've tried the same query in SQL Server 2008 where the query fails (error: the column prefix does not match with a table name or alias used in the query). For reasons of pure curiosity I have been trying to figure out how SQL Server 2000 handles the table names in a way that would allow the butter-fingered query to run, but I haven't had much luck so far. Any sql gurus know why SQL Server 2000 ran the query without issue? Update: The query appears to work regardless of the interface used (e.g. Enterprise Manager, SSMS, OSQL) and as Jhonny pointed out below it bizarrely even works when you try: SELECT TOP 1000 dbota.ble.* FROM dbo.table

    Read the article

  • How do you write a recursive stored procedure

    - by Grayson Mitchell
    I simply want a stored procedure that calculates a unique id and inserts it. If it fails it just calls itself to regenerate said id. I have been looking for an example, but cant find one, and am not sure how I should get the sp to call itself, and set the appropriate output parameter. I would also appreciate someone pointing out how to test this sp also. ALTER PROCEDURE [dbo].[DataContainer_Insert] @SomeData varchar(max), @DataContainerId int out AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; BEGIN TRY SELECT @UserId = MAX(UserId) From DataContainer INSERT INTO DataContainer (UserId, SomeData) VALUES (@UserId, SomeData) SELECT @DataContainerId = scope_identity() END TRY BEGIN CATCH --try again exec DataContainer_Insert @DataContainerId, @SomeData END CATCH END

    Read the article

  • Update Empty XML Tag in SQL Server

    - by monO
    I'm trying to update an empty XML Tag in my Xml string on sql server; it says the row is updated when i run the following script, but when I view the XML; nothing has changed: Declare @newValue varchar(100) select @newValue = '01' update dbo.UploadReport set XmlTest.insert('replace value of (/CodeFiveReport/Owner/AgencyID/text())[1] with sql:variable("@newValue")') where id = 'myId' The xml after still appears as this in the databse <AgencyID /> What am I doing wrong? I've tried @AgencyID without the text() at the end and still no avail...

    Read the article

  • SQL use comma-separated values with IN clause

    - by user342944
    I am developing an ASP.NET application and passing a string value like "1,2,3,4" into a procedure to select those values which are IN (1,2,3,4) but its saying "Conversion failed when converting the varchar value '1,2,3,4' to data type int." Here is the aspx code: private void fillRoles() { /*Read in User Profile Data from database */ Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("sp_getUserRoles"); db.AddInParameter(cmd, "@pGroupIDs", System.Data.DbType.String); db.SetParameterValue(cmd, "@pGroupIDs", "1,2,3,4"); IDataReader reader = db.ExecuteReader(cmd); DropDownListRole.DataTextField = "Group"; DropDownListRole.DataValueField = "ID"; while (reader.Read()) { DropDownListRole.Items.Add((new ListItem(reader[1].ToString(), reader[0].ToString()))); } reader.Close(); } Here is my procedure: CREATE Procedure [dbo].[sp_getUserRoles](@pGroupIDs varchar(50)) AS BEGIN SELECT * FROM CheckList_Groups Where id in (@pGroupIDs) END

    Read the article

  • SQL Drop Index on different Database

    - by Jim
    While trying to optimize SQL scripts, I was recommended to add indexes. What is the easiest way to specify what Database the index should be on? IF EXISTS (SELECT * FROM sysindexes WHERE NAME = 'idx_TableA') DROP INDEX TableA.idx_TableA IF EXISTS (SELECT * FROM sysindexes WHERE NAME = 'idx_TableB') DROP INDEX TableB.idx_TableB In the code aboce, TableA is in DB-A, and TableB is in DB-B. I get the following error when I change DROP INDEX TableA.idx_TableA to DROP INDEX DB-A.dbo.TableA.idx_TableA Msg 166, Level 15, State 1, Line 2 'DROP INDEX' does not allow specifying the database name as a prefix to the object name. Any thoughts are appreciated.

    Read the article

  • Trying to send text message using sp_send_dbmail truncates url in body

    - by Dabas
    I'm using send_dbmail to send a text message to customers. This is the following sql: exec msdb.dbo.sp_send_dbmail @recipients='[email protected]', @body='check out this url https://www.someurl.com/directory/blah.aspx', @subject='I am the subject!' The body gets truncated to "check out this url https://www.someurl.com/directory/blah.as" (the "px" is removed from the end of the url). I've ruled out message length as I have tried sending just "www.google.com/test.aspx" and the "px" is removed as well. Another strange thing, when I try forwarding the text message to myself and add the "px" back on myself, it works. It also works if I send a email from outlook with the same body. Any ideas? Thanks.

    Read the article

  • what is wrong with my create table SQL?

    - by George2
    Hello everyone, I am using SQL Server 2008 management studio to execute the following SQL statements, and here is the related error message from SQL Server management studio. Any ideas what is wrong? SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO Create TABLE [dbo].[BatchStatus]( [BatchID] [uniqueidentifier] NOT NULL CONSTRAINT [PK_BatchStatus_ID], [BatchStatus] [int] NULL, CONSTRAINT [PK_BatchStatus_ID] PRIMARY KEY CLUSTERED ( [BatchID] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] GO Msg 102, Level 15, State 1, Line 3 Incorrect syntax near ','. Msg 319, Level 15, State 1, Line 8 Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon. thanks in advance, George

    Read the article

  • For LinqToSQL is 0 true or is 1 (for type Bit)?

    - by Vaccano
    I have a column of type Bit (called BBoolVal in this example). I have a LinqToSQL Statement Like this: var query = List<MyClass> myList = _ctx.DBList .Where(x => x.AGuidID == paramID) .Where(x => x.BBoolVal == false); When I look at the sql it ends up like this (I added the spacing and changed the names): SELECT [t0].[Id], [t0].[AGuidID], [t0].[OtherIDID], [t0].[TimeColumn], [t0].[BBoolVal], [t0].[MoreID] FROM [dbo].[MyTable] AS [t0] WHERE (NOT ([t0].[BBoolVal] = 1)) AND ([t0].[AGuidID] = @p0) Because my x.BBoolVal == false translates to [BBoolVal] == 1 I gather that false = 1 (and thus true = 0). I am asking because this seems a bit backwards to me. I am fine to accept it, I just want to be sure.

    Read the article

  • Next Identity Key LINQ + SQL Server

    - by user569347
    To represent our course tree structure in our Linq Dataclasses we have 2 columns that could potentially be the same as the PK. My problem is that if I want to Insert a new record and populate 2 other columns with the PK that was generated there is no way I can get the next identity and stop conflict with other administrators who might be doing the same insert at the same time. Case: A Leaf node has right_id and left_id = itself (prereq_id) **dbo.pre_req:** prereq_id left_id right_id op_id course_id is_head is_coreq is_enforced parent_course_id and I basically want to do this: pre_req rec = new pre_req { left_id = prereq_id, right_id = prereq_id, op_id = 3, course_id = query.course_id, is_head = true, is_coreq = false, parent_course_id = curCourse.course_id }; db.courses.InsertOnSubmit(rec); try { db.SubmitChanges(); } Any way to solve my dilemma? Thanks!

    Read the article

  • question about LocalSqlServer

    - by Alexander
    I know that by default ASP.NET ships with LocalSqlServer... I just uploaded my website and I did the following: <remove name="LocalSqlServer"/> <add name="LocalSqlServer" connectionString="Data Source=winsqlus03.lxa.perfora.net,1433; Initial Catalog=db323219488; User ID= dboxxxxxxxxx; Password=xxxxx;"/> And inside my App_Data I still have the ASPNETDB.MDF, when I tried to run it... What I got is: Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'. why is this?

    Read the article

  • What is the maximum length of a string parameter to Stored procedure?

    - by padmavathi
    I have a string of length 1,44,000 which has to be passed as a parameter to a stored procedure which is a select query on a table. When a give this is in a query (in c# ) its working fine. But when i pass it as a parameter to stored procedure its not working. Here is my stored procedure where in i have declared this parameter as NVARCHAR(MAX) ------------------------------------------------------ set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go CREATE PROCEDURE [dbo].[ReadItemData](@ItemNames NVARCHAR(MAX),@TimeStamp as DATETIME) AS select * from ItemData where ItemName in (@ItemNames) AND TimeStamp=@TimeStamp --------------------------------------------------------------------- Here the parameter @ItemNames is a string concatinated with different names such as 'Item1','Item2','Item3'....etc. Can anyone tell what went wrong here? Thanks & Regards Padma

    Read the article

  • TSQL - create a stored proc inside a transaction statement

    - by Chris L
    I have a sql script that is set to roll to production. I've wrapped the various projects into separate transactions. In each of the transactions we created stored procedures. I'm getting error messages Msg 156, Level 15, State 1, Line 4 Incorrect syntax near the keyword 'procedure'. I created this example script to illustrate Begin Try Begin Transaction -- do a bunch of add/alter tables here -- do a bunch of data manipulation/population here -- create a stored proc create procedure dbo.test as begin select * from some_table end Commit End Try Begin Catch Rollback Declare @Msg nvarchar(max) Select @Msg=Error_Message(); RaisError('Error Occured: %s', 20, 101,@Msg) With Log; End Catch The error seems to imply that I can't create stored procs inside of transaction, but I'm not finding any docs that say otherwise(maybe google isn't being freindly today).

    Read the article

  • Identifying when there is more than 1 in a group based on grouped field

    - by Brian Cascone
    Sorry for the bad description it is tough to explain in one sentence. I have a dataset that has Cause field (RootCause) and an ID field (GroupID). Both can be many things but I need to identify where a GroupID has a multiple different rootcauses. for example: RootCause GrpId AAA 111 BBB 222 CCC 111 I am looking to be able to identify that GrpId 111 has two different RootCauses. This is what I have so far: Select [RootCause], GrpId, Count(GrpID) as CntGrpId From DB.dbo.Table Where DatatypeField <> '' Group BY [RootCause],GrpId This results set visualy gives me enough information to identify what I am looking for, but i need something better. I am looking to return only the ones that have multiples. Any ideas? Thanks

    Read the article

  • Sql Server query performance

    - by Macros
    I have a stored procedure on a busy database which constantly come out top in the list of expensive queries (by some way). The query is very simple, it takes a single parameter (@ID, int) which is the primary key of the table, and selects the record that matches that ID. The primary key is an identity field with a clustered index, so I am stumped as to how to optimise this any further? The query is as follows CREATE PROCEDURE [dbo].[P_Call_Get] @ID int = null AS select ID, AppID, AgentID, AgentLogin, Ext, VDN, VDNName, Skill, SkillName, CallFrom, TelNoFrom, ParentCallID, CallStart, ACWStart, CallEnd, Outcome, StageID, TxTo, TxSuccess, ServiceID, DiallerID, CRC, TSCallID, CallDirection, [Manual], CallBackAgent, CallBackDateTime, Notes from P_Call where (ID = @ID or @ID is null) Not sure the best way to post the execution plan - all it shows is that 100% of the operation is taken up by the clustered index scan

    Read the article

  • Check for duplicate rows in 2 columns before update

    - by user3891378
    I have a table with 4 columns, and I need to check to see if a Column Pair exists before inserting a row into the database: INSERT INTO dbo.tblCallReport_Detail (fkCallReport, fkProductCategory, Discussion, Action) VALUES (?, ?, ?, ?) The pair in question is fkCallReport and fkProductCategory. For example if the row trying to be inserted has fkCallReport = 3 and fkProductCategory = 5, and the database already has both of those values together, it should display an error and ask if they would like to combine the Disuccsion and Action with the current record. Keep in mind I'm doing this in VBA Access 2010 and am still very new.

    Read the article

  • Return Empty String as NULL

    - by Daniel
    I have a listbox select and I want when the user selects null for the empty string it produces to pull the nulls from the SQL table. Here's what I have now. Blank strings return nothing because there are no empty fields in the table. SELECT * FROM dbo.Table WHERE ID = " & TextBox2.Text & " and And Field1 IN (" & Msg1 & ") How do I code that?

    Read the article

  • Encryption By Certificate

    - by user1817240
    I am encrypting customer name in database at database level. While saving in database only first letter of customer name is saved and hence while decrypting only first letter is retrieved. The following code shows the test sp. ALTER PROCEDURE [dbo].[spc_test_insert] ( @sFIRST_NAME typ_encryptedtext, ) AS BEGIN DECLARE @sSENCRYPTION_KEY char(15) DECLARE @sCERTIFICATE char(22) SET @sSENCRYPTION_KEY='SymmetricKey1' SET @sCERTIFICATE='CustomerCertificate' OPEN SYMMETRIC KEY SymmetricKey1 DECRYPTION BY CERTIFICATE CustomerCertificate; INSERT INTO test_table ( FIRST_NAME, ) Values ( -- Add the Params to be Added... EncryptByKey(Key_GUID(@sSENCRYPTION_KEY),@sFIRST_NAME), ) CLOSE SYMMETRIC KEY SymmetricKey1 END encryption decryption working fine in normal insert but its not working in stored procedure.

    Read the article

  • SQL 2000 Multiple IF Statements

    - by Spidermain50
    I get a error when I try to use multiple IF statements. This is the error... "Msg 156, Level 15, State 1, Procedure fnTNAccidentIndicator, Line 81 Incorrect syntax near the keyword 'END'." This is the structure of my code... USE SS_TNRecords_Accident SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION dbo.fnTNAccidentIndicator ( @inAccidentNumber nvarchar, @inIndicatorMode int ) RETURNS nvarchar AS BEGIN DECLARE @AlcoholInd nvarchar DECLARE @DrugInd nvarchar DECLARE @SpeedInd nvarchar DECLARE @ReturnValue nvarchar SET @AlcoholInd = '1' SET @DrugInd = '2' SET @SpeedInd = '3' SET @ReturnValue = 'N' IF (@inIndicatorMode = @AlcoholInd) BEGIN --select statment IF (@@ROWCOUNT > 0) BEGIN @ReturnValue = 'Y' END END IF (@inIndicatorMode = @DrugInd) BEGIN --select statment IF (@@ROWCOUNT > 0) BEGIN @ReturnValue = 'Y' END END IF (@inIndicatorMode = @SpeedInd) BEGIN --select statment IF (@@ROWCOUNT > 0) BEGIN @ReturnValue = 'Y' END END Return @ReturnValue END GO

    Read the article

  • Why is [date] + [time] non-deterministic in SQL Server 2008?

    - by John Gietzen
    I'm trying to do the following for my IIS logs table: ALTER TABLE [W3CLog] ADD [LogTime] AS [date] + ([time] - '1900-01-01') PERSISTED However, SQL Server 2008 tells me: Computed column 'LogTime' in table 'W3CLog' cannot be persisted because the column is non-deterministic. The table has this definition: CREATE TABLE [dbo].[W3CLog]( [Id] [bigint] IDENTITY(1,1) NOT NULL, ... [date] [datetime] NULL, [time] [datetime] NULL, ... ) Why is that non-deterministic? I really need to index that field. The table currently has 1598170 rows, and it is a pain to query if we can't do an index seek on the full time. Since this is being UNION'd with some other log formats, we can't very easily just use the two columns separately.

    Read the article

  • Check If Stored Procedure Returns Value

    - by Eric
    Hello all, I am using Linq 2 Sql in VS 2010, and I have the following stored procedure to check a username and password ALTER PROCEDURE dbo.CheckUser ( @username varchar(50), @password varchar(50) ) AS SELECT * FROM Users Where UserName=@username AND Password=@password The problem I'm having is that it throws an exception if the username and password are incorrect. I'd like to perform a check to see if there is a return value, rather than using try/catch to determine whether the procedure returned a value. Should I do this check in code (C#)? Or is there a way to do it in SQL? Thanks.

    Read the article

  • SQL and multiple statements in stored procedure

    - by Sjemmie
    I'm working on SQL server 2005 and I have a very simple stored procedure: create PROCEDURE [dbo].[tblTabel_Insert] @ID int, @Code nvarchar(50) = null AS SET NOCOUNT ON; IF EXISTS (SELECT ID, code FROM tblTabel WHERE ID = @ID and code = @Code) UPDATE tblTabel SET ID = @ID,code = @Code WHERE ID = @ID ELSE BEGIN INSERT INTO tblTabel (ID,code) VALUES ( @ID ,@Code); END My question is: is it posible to have multiple queries in my stored procedure ? I want to add the lines UPDATE tblTabelB SET ID = @ID,code = @Code WHERE ID = @ID UPDATE tblTabelC SET ID = @ID,code = @Code WHERE ID = @ID in my if exists section. How do I change my stored procedure in the correct way ?

    Read the article

  • Number 0 is not saving to database as a prefix in SQL Server of CHAR data type column

    - by gmhk
    I am trying to insert an value as '019393' into a table with a CHAR(10) column. It is inserting only '19393' into the database I am implementing this feature in a stored procedure, doing some manipulation like incrementing that number by 15 and saving it back with '0' as the prefix I am using SQL Server database Note: I tried CASTING that value as VARCHAR before saving to the database, but even that did not get the solution Code SELECT @fromBSB = fromBSB, @toBSB = toBSB, @type = Type FROM [dbo].[tbl_REF_SpecialBSBRanges] WHERE CAST(@inputFromBSB AS INT) BETWEEN fromBSB AND toBSB SET @RETURNVALUE = @fromBSB IF(@fromBSB = @inputFromBSB) BEGIN PRINT 'Starting Number is Equal'; DELETE FROM tbl_REF_SpecialBSBRanges WHERE Type = @type AND fromBSB = @fromBSB AND toBSB = @toBSB INSERT INTO [tbl_REF_SpecialBSBRanges] ([Type], [fromBSB], [toBSB]) VALUES(@type, CAST('0' + @fromBSB + 1 AS CHAR), @toBSB) INSERT INTO [tbl_REF_SpecialBSBRanges] ([Type], [fromBSB], [toBSB]) VALUES(@inputBSBName, @inputFromBSB, @inputToBSB) END

    Read the article

< Previous Page | 32 33 34 35 36 37 38 39 40 41 42 43  | Next Page >