Pages

Thursday, November 29, 2012

Dynamic query and Varbinary


Recently, I came across a strange issue when working with dynamic SQL query along with varbinary data type. I need to insert user’s uploaded image into database.

Because I have multiple varbinary columns to store images, I thought of using single stored procedure to handle insert or updated and that too with single varbinary input parameter along with the intended column.

We build dynamic SQL query and formatted it with the column name as well as binary array (image) content as input parameter. See below:

Set @Query = 'INSERT INTO [dbo].[DashboardImage]( [MemberID], ' + @Field + ')VALUES('+ convert(varchar(max), @MemberID) +','+ cast(@Value as varchar(max)) +')'

Where the input parameter declared as:

@Value varbinary(max),
@Field varchar(200),

When compiled everything was fine. However, when executed with input parameters the query produces type conversion errors like "Cannot convert value from varchar to varbinary" or “Explicit conversion from data type  to varchar is not allowed” or "String or binary data would be truncated."

After going through online resources I got a solution as predefined function “master.dbo.fn_varbintohexstr(@Value)” within Master database which will convert varbinary data type to a varchar or string.

So, here is the new dynamic query which solved our problem

Set @Query =  'INSERT INTO [dbo].[DashboardImage]( [MemberID], ' + @Field + )VALUES('+ convert(varchar(max), @MemberID) +','+ master.dbo.fn_varbintohexstr(@Value) + ')'

And finally to execute the query

EXEC(@Query)



Happy Coding

Thursday, November 15, 2012

10 Outdated Management Practices to stop today

You might not feel it day-to-day, but business management is in a major transition.  The old days of command-and-control leadership are fading in favor of what might be better termed a trust-and-track method, in which people are not just told what to do, but why they are doing it.  More formally, we're moving from what was called "transactional" leadership to "transformative" leadership. And there's no turning back.

Here's my list of "old school" practices you ought to chuck, and "new school" practices to champion instead:

#1
Out: Micro-management, or the need to control every aspect of your company.
In: Empowerment, the ability to give your people some rope--even rope to make mistakes without blame.

#2
Out: Management by walking around the office; it is no longer enough to be visible.
In: Leadership by watching and listening, engaging in conversation, implementing the ideas presented to you, and distributing the results.

#3
Out: Pretending you know everything. You don't have all the answers, so why try to make people think you do?
In: Knowing your leadership team members and trusting them. Choose great people who have the right skills and fit the culture.  And get out of the way.

#4
Out: No mistakes, or a "no tolerance policy" some still think works.
In: Learning from mistakes, or being the first to admit an error.

#5
Out: The balance sheet drives the business, and informs all other decisions.
In: People drive the business, boosting customer loyalty, and profit.

#6
Out: Job competency is sufficient. Do the job asked, and you'll survive.
In: Recruit "A" players who will go the extra mile. They're out there.

#7
Out: Invest in technology to increase productivity.
In: Invest in people.

#8
Out: Demand change; be very specific about what you want and when.
In: Nurture change; your people can come up with the best ideas and you can give them credit for it.

#9
Out: Fried food in the cafeteria.
In: Wellness in the workplace.

#10
Out: Incentives; pay employees more money and they'll do more.
In: Rewards; being valued matters more than money.

So ask yourself which of these out-of-date practices you're still using.

Original Post

Saturday, November 10, 2012

24 hr Gold Index

Here you can get the current international Gold index in Rupees (र - INR) per Gram

[Most Recent Quotes from www.kitco.com]


The actual market market may vary depending upon your location

Bookmark this page to get updated Gold index in rupees.

Thursday, November 8, 2012

24 hr USD - INR Value

Here you can find the current Indian Rupee (र - INR) index against US Dollar ($ - USD)

[Most Recent Exchange Rate from www.kitco.com]


Bookmark this page to your browser and get updated INR value against USD