Thursday, May 16, 2013

[SQL Server 2008 issues] Case with Wildcards

SQLServerCentral / SQL Server 2008 / SQL Server 2008 - General

[SQL Server 2008 issues] Case with Wildcards


Case with Wildcards

Posted: 15 May 2013 08:31 AM PDT

I am having trouble with a CASE statement like this.The All Cars doesn't work.SELECT CASEWHEN CARS.Model LIKE '%Ford%' THEN 'Ford'WHEN CARS.Model LIKE '%Chev%' THEN 'Chev'WHEN CARS.Model LIKE '%Buick%' THEN 'Buick'WHEN CARS.Model LIKE '%' THEN 'All Cars'END AS 'Models'

Query result

Posted: 15 May 2013 11:55 AM PDT

[code="other"]DECLARE @SQL NVARCHAR(MAX)='' DECLARE @LinkNumber INT DECLARE @LinkCount INT=0 DECLARE @LinkTable NVARCHAR(101)='' SELECT @LinkNumber= NoOfLinks FROM [ABC].[dbo].[MyTable] WHERE TableID=7 IF @LinkNumber>0 BEGIN SET @LinkCount=1 WHILE (@LinkCount<=@LinkNumber) BEGIN SET @LinkTable=QUOTENAME('LinkTable'+CAST(@LinkCount AS NVARCHAR(2))) SELECT @LinkTable= @LinkTable FROM [ABC].[dbo].[MyTable] WHERE TableID=7 SET @SQL='DELETE lnk FROM ABC.dbo.'+@LinkTable+' lnk JOIN #TempVID Temp ON lnk.hubVID=Temp.TempVID' SET @LinkCount=@LinkCount+1 SET @LinkTable=NULL PRINT (@SQL) END END [/code]The Code above generates a query like DELETE lnk FROM ABC.dbo.[LinkTable1] lnk JOIN #TempVID Temp ON lnk.hubVID=Temp.TempVIDDELETE lnk FROM ABC.dbo.[LinkTable2] lnk JOIN #TempVID Temp ON lnk.hubVID=Temp.TempVIDBut what i really wanted to do is have is have it generate it query where it has the Value of LinkTable1, LinkTable2..and so forth. I tried around a bunch of things and it doesn't work unless the column name is hardcoded. Any suggestions? thanks.

Import Excel File to SQL Server

Posted: 15 May 2013 02:02 AM PDT

I am having trouble while importing excel file to SQL Server.Excel File:ColumnA--------b22a2a2aaWhen I import...it comes asColumnA--------b2a2a2aaJust number "2" doesn't comes.I tried datatype mapping as varchar(512)and if I change datatype to float then only numeric value comes and rest of data is comes as blank. I need to all the data.Can you please tell me which datatype should I use.Thanks in advance.

Red Gate Sql Monitor Alert is downgraded but still shows as HIGH

Posted: 15 May 2013 01:38 AM PDT

HiI have been reorganising/rebuilding some indexes due to high fragmentation due to an alert generated by Red Gates sqlmonitor.I have ran some scripts and done the required steps to get the indexes back in shape.The alert moves to the top of the pile and when i hover my mouse over the 'status' it says 'downgraded' with the time - however i still have the red alert box which says 'high' - this shoud now read 'low' or the alert should maybe be totally cleared if my index rebuild truly did its job !How can i get the red alert box to change to what it should reflect after the downgraded process ?Thanks

Tracing failed SP call

Posted: 15 May 2013 11:21 AM PDT

Does anyone know if its possible to trace failed SP calls through Profiler? For example, if you call an SP without a required param, it red inks but nothing shows up in the trace to identify the failed proc call. This would be helpful when debugging errors in a binaries data access.Thanks in advance.

update statement - what's the locking/blocking risk?

Posted: 15 May 2013 09:37 AM PDT

Hello - I recently added a new column to a db table with 6.5 million rows. Now I need to populate this column data from another data source by joining on a column between this db table and the other data source.Since this table has 6.5 million rows I'm wondering if there's a risk of table/row locking/blocking with this update statement?How would you normally handle this type of update statement? Are there any special precautions you would take and does the large number of rows impact how you would implement this update statement?

code folding in ssms?

Posted: 10 May 2013 06:37 AM PDT

Hello - What are some techniques you use for code folding in SSMS? For example, in Visual Studio you can add regions like this:#region Protected Methods//some code here

No comments:

Post a Comment

Search This Blog