Forum: MS SQL Apr 3rd, 2009 |
| Replies: 2 Views: 790 Stored procedures need to be created using the CREATE PROCEDURE statement and then executed (F5 or the green play button in the toolbar). They are compiled and stored in the database itself. If you... |
Forum: MS SQL May 27th, 2008 |
| Replies: 11 Views: 7,050 (Holyl is now bald as a coot)
I think EXEC @tsql needs to be EXEC(@tsql) with parenthesis.
and getting the error:-
The name 'ALTER TABLE [] ADD []' is not a valid identifier.
To me this... |
Forum: MS SQL May 27th, 2008 |
| Replies: 11 Views: 7,050 (Holly pulls his hair out ....) I see an important space disappeared in my second post! gah! ok use this:
Spot the difference:
--CORRECT CODE
SET @tsql = 'ALTER TABLE [' + @tablename + '] ADD... |
Forum: MS SQL May 23rd, 2008 |
| Replies: 11 Views: 7,050 The table must exist in the database.
Also you have now introduced spaces between the [ and the table name, you need to remove those, same for the column name unless you want lots of subtle bugs... |
Forum: MS SQL May 23rd, 2008 |
| Replies: 11 Views: 7,050 Here's a tip: amend the stored proc to select @tsql instead of EXEC(@tsl)
CREATE PROCEDURE sp_addcolumn
-- Add the parameters for the stored procedure here
@TABLE_NAME varchar(50) = 0, ... |
Forum: MS SQL May 23rd, 2008 |
| Replies: 11 Views: 7,050 Alter table can't take dynamic parameters. To do this you will have to concatenate the whole TSQL command as a string dynamically and then execute it. Also you don't need the COLUMN keyword.
... |
Forum: MS SQL May 9th, 2008 |
| Replies: 6 Views: 1,496 It's late and I'm a little blurry. But from what I can see in your query I think this: tDocumentsA.user_id = tUsers.contact_id should be: tDocumentsA.user_id = tUsers.id (the same for all document... |
Forum: MS SQL Mar 13th, 2008 |
| Replies: 7 Views: 17,549 Oops we posted at same time. When restoring you will have to tweek some options: 1. the name for the database (cos it doesn't exist on the new server yet) just type it in the drop down box. And 2.... |
Forum: MS SQL Mar 13th, 2008 |
| Replies: 7 Views: 17,549 Right click the database -> Tasks -> Back Up...
More info here (quite a way down it looks at SSMSEE in depth) Just CTRL + F for 'Backup'.
... |
Forum: MS SQL Mar 13th, 2008 |
| Replies: 7 Views: 17,549 Do a complete backup, copy the file to the other server and restore it there.
Or you can detach the database, copy the .mdf and .ldf files zip them up and copy them over to the new server, unzipp... |
Forum: MS SQL Mar 13th, 2008 |
| Replies: 10 Views: 1,438 There is a SQL standard but each implementatin has it's own quirks on top of that. The only cure for this is experience. INNER JOIN is the assumed default in TSQL so you can be lazy and just type... |
Forum: MS SQL Mar 12th, 2008 |
| Replies: 10 Views: 1,438 MS Access !! yuck !! You didn't say you were using Access, and as this is a MS SQL Forum I used TSQL.
Ok just for you I have recreated everything in Access and tweaked the SQL. Basically removed... |
Forum: MS SQL Mar 12th, 2008 |
| Replies: 2 Views: 980 That works. Also there is TSQL's ISNULL function.
SELECT
ISNULL(FirstColumn, '') + ' ' + ISNULL(SecondColumn, '') AS ResultColumn
FROM
mytable |
Forum: MS SQL Mar 12th, 2008 |
| Replies: 10 Views: 1,438 Excellent. Please mark thread solved :) |
Forum: MS SQL Mar 12th, 2008 |
| Replies: 3 Views: 1,810 Fee Fi Fo Fum I smell the blood of a Tsql Cursor, be he slow or be he slower, I'll grind his bones with my set theory mower.
Sorry I'm on a personal crusade against cursors :)
I offer my own... |
Forum: MS SQL Mar 12th, 2008 |
| Replies: 10 Views: 1,438 Hmm re-reading your post that may not be quite what you want, you want lowest quote regardless of vendor I think.
select
q.[ID],
q.item,
v.[name],
mq.minprice,
v.phone#,
v.fax# ... |
Forum: MS SQL Mar 12th, 2008 |
| Replies: 10 Views: 1,438 Firstly just join the quote_tb to the vendor_tb. That gives the vendor details for ALL quotes.
Then use GROUP BY (to merge up all the repeating colums (ID, item, name, phone#, fax#) and the... |
Forum: MS SQL Mar 12th, 2008 |
| Replies: 1 Views: 518 Whch version? and depends on what was installed (typical/custom)
Just type services.msc into Start -> Run
Scroll down to Services beginning with M and S
Services names are prefixed... |
Forum: MS SQL Mar 7th, 2008 |
| Replies: 2 Views: 948 You can do it with a sub query:
SELECT
C,
F,
I,
C * F AS total1,
F * I AS total2,
C * I AS total3, |
Forum: MS SQL Mar 5th, 2008 |
| Replies: 6 Views: 1,255 Start -> Run
type 'cmd' (without quotes) press enter
at the command prompt type:
>net start "Sql Server (SQLEXPRESS)"
Press enter
This ensures the service is running, if it's already started... |
Forum: MS SQL Jan 25th, 2008 |
| Replies: 5 Views: 941 Hmm not really, it replaces the assumption that a.id is a foreign key to b.id.
The OP does not specify. If there is a relation between the id's (which there should be in my opinion, and if the... |
Forum: MS SQL Jan 24th, 2008 |
| Replies: 5 Views: 941 Or maybe:
select b.id, isnull(a.name,b.name) as [Name] from b
left join a on b.[Name] = LEFT(a.[Name],1) |
Forum: MS SQL Nov 1st, 2007 |
| Replies: 6 Views: 7,383 |
Forum: MS SQL Oct 29th, 2007 |
| Replies: 3 Views: 2,170 >What is the (1,1) for?
It seeds the identity. Its beginning value and step. You could start at 10 and increment in steps of 10 for example (10,10) so inserts would go; 10,20,30,40 ...
>will I... |
Forum: MS SQL Oct 29th, 2007 |
| Replies: 3 Views: 2,170 Question: Why are you explicitly allowing nulls in your primary key column?
for primary keys (two syntactical options):
1.
BCustID INT IDENTITY(1,1) NOT NULL PRIMARY KEY
or 2.
constraint... |
Forum: MS SQL Oct 15th, 2007 |
| Replies: 2 Views: 10,167 SET IDENTITY_INSERT <tablename> ON
Place this statement before your insert statement, it allows you to enter specific id's into an identity seed column. Place this line immediately after your... |
Forum: MS SQL Sep 25th, 2007 |
| Replies: 2 Views: 3,920 You can install it separately.
http://www.microsoft.com/downloads/details.aspx?FamilyID=d09c1d60-a13c-4479-9b91-9e8b9d835cdc |
Forum: MS SQL Sep 21st, 2007 |
| Replies: 4 Views: 1,280 Pardon ?????
I have given you enough to solve the problem. You have changed your schema, what happened to the date column? Now I only have the orderid to key off and assume it's an increasing... |
Forum: MS SQL Sep 21st, 2007 |
| Replies: 8 Views: 2,120 Sql Server 2000 or 2005 ? I ask as it depends what GUI to use for the following TSQL code. Sql 2000 Start->Programs->Ms Sql Server->Query Analyser File->Connect click OK, select the database name in... |
Forum: MS SQL Sep 20th, 2007 |
| Replies: 4 Views: 1,280 Untested but this should be close if not perfect. Basically you need to group up the order table to reduce it to just the most recent (max) date for each customer id (this is a sub-query) then you... |
Forum: MS SQL Aug 15th, 2007 |
| Replies: 1 Views: 2,820 You have to concatonate a TSQL string first and then execute it dynamically.
declare @tsql nvarchar(4000)
declare @dbName varchar(32)
set @dbName = 'dbName'
set @tsql = 'use ' + @dbName... |
Forum: MS SQL Apr 25th, 2007 |
| Replies: 1 Views: 1,401 How are you generating the HTML table ? PHP, ASP, ASP.NET ?
Basically though yes you can store the string
'<a href="somepage">click me</a>' in a nvarchar field for example. |
Forum: MS SQL Apr 17th, 2007 |
| Replies: 7 Views: 10,014 In Sql Server Management Studio, expand databases, right click your database and choose tasks -> Export. In the first wizard page choose the source (this should already be the databse you just right... |
Forum: MS SQL Apr 16th, 2007 |
| Replies: 7 Views: 10,014 In Sql Server Management studio expand databases on the left, expand the database that contains your tables, right click on Database diagrams and choose 'New database diagram', you may at this point... |
Forum: MS SQL Apr 11th, 2007 |
| Replies: 8 Views: 19,036 OK so I set up a database as follows:
IF EXISTS(SELECT * FROM sysdatabases WHERE name='DBmyUnmatchedTest')
DROP DATABASE DBmyUnmatchedTest
GO
create database DBmyUnmatchedTest
GO |
Forum: MS SQL Apr 11th, 2007 |
| Replies: 8 Views: 19,036 Hmm my gut feeling is it isn't, but I also know the only way to be sure is to test it for ourselves using profiler and looking at the query plan for each scenario, which could give me some material... |
Forum: MS SQL Apr 11th, 2007 |
| Replies: 8 Views: 19,036 No the default JOIN specifys only records that match, the default join is INNER.
LEFT OUTER JOIN (can be abreviated to LEFT JOIN) means all records in left table whether there's a match in the... |
Forum: MS SQL Apr 11th, 2007 |
| Replies: 8 Views: 19,036 try DISTINCT
eg: select distinct * from table1 join table2 on blah... |
Forum: MS SQL Apr 11th, 2007 |
| Replies: 4 Views: 6,192 Hey no problem glad I could help. |
Forum: MS SQL Apr 3rd, 2007 |
| Replies: 5 Views: 3,954 In fact why use a trigger OR a function. Consider this:
create table #exam
(
e_id int identity(1,1) primary key,
e_score int,
e_note nvarchar(4)
) |