Actually you are not giving the size of varchar so by default it will take varchar(1) and you will not be able to insert the record which is greater than 1 character. You have to do like this:- Create Table Purchase (Name varchar(50),Amount numeric(10,2))
neeraj_indianic
Posts
-
Create Table statement -
datetime problemThis is because of format of date is different in your table column field(i.e. CreateDate and you are comparing this date with another format which is mm/dd/yyyy. If you want to do it then you have to convert your format and you will sure get result. Now use this query to get the result.
select tU.UserID,tU.FirstName,tU.LastName, tU.LastName+''+ tU.FirstName'UserId', tA.UserID,tA.CreateDate, tA.UpdateDate from tAnalyst tA, tUser tU where tU.UserID=tA.UserID and convert(varchar,tA.CreateDate,101)='07/25/2007'
-
Cursor_sql server 2005Instead of using select * from #temp21 specify the each column name and in the date column use convert function. now your select query will be like this.
select convert(varchar,Ason,101),SubScriberEmailfrom, convert(varchar,SvcActivationDate,101),convert(varchar,PkgActivationDate,101), convert(varchar,RenewalDate,101) from #temp21
-
Doubt in StoredProcedure [modified]ok, Now i got your problem and your solution is given here.
set @sql='select *from tblname where '+@columnname+' = '+''''+@value+''''
I have tried it and its working. -
Doubt in StoredProcedure [modified]Just check your table detail. It will be because of you have defined the column name as int while creating the table.
-
in sql server 2005 i need to send e mails periodically.Using db you can not send the mail periodically. But this method will help you. Create an excutable file which contains sending mail code. Schedule this excutable file using windows scheduler from control panel. Now your executable file will check the pending mails from your db and will send the mail. Once mail is sent then set the flag sent so that it will not sent again.
-
select statement to another database on another serverI have seen that to use OPENROWSET command the first parameter should be MSDASQL the SQLOLEDB is used for OPENDATASOURCE. i have tried this query and working perfectly. Also i hope that you have already enabled the OPENROWSET and OPENDATASOURCE command from the SQL server surface area configuration wizard. SELECT * FROM OPENROWSET('MSDASQL', 'DRIVER={SQL Server};SERVER=yourremoteserver_name;UID=your_remote_user_id;PWD=your_remote_password', your_remote_database_name.dbo.remote_table_name) Neeraj Gupta
-
how to capture count of records from stored procedrureYou can use @@ROWCOUNT in your stored procedure and take the value returned by @@ROWCOUNT as output parameter of stored procedure.
-
cursors in functionsYou have not specified that which type of function you want to create means scalar valued function or table valued function. I suppose that you want to create table valued function. For that your code is wrong in the starting line. Look at the below code. Hope it will guide you. CREATE FUNCTION [dbo].[waste]() RETURNS @student1 TABLE ( student_rec int, St_name nchar(10) ) AS Begin declare @a int declare @b nchar(10) declare cur cursor for select Id,name from student open cur fetch next from cur into @a,@b while @@FETCH_STATUS =0 BEGIN INSERT @student1 values(@a,@b) --SELECT @a as a1 , @b as a2 fetch next from cur into @a , @b END close cur deallocate cur RETURN end Neeraj Gupta IndiaNIC Infotech Ltd.